reinterpret_cast and use with CV_MAT_ELEM
i want to put all the data of an 8 bit input colorimage (Inputfile is a.bmp file)
in a new 16 bit Mat Array.

I do this because i need to sum up several image patches and then build the meanvalue for each pixel.

    Mat img = imread(Inputfile);   //there now should be values between 0 and 255 

Addressing the blue value for example like follows 

    uchar* ptr = img.data + img.step*row;
    cout << ptr[n*col] << endl;
    

only brings up single Letters and no values.

    cout << static_cast<short>(ptr[n*col]) << endl;

Typecasting to short or bigger brings up the correct values. but a cast to unsigned char (which is the correct datatype in my opinion) brings up the same Letters than without any typecast.


Short has 2 Bytes as i know, but a color .bmp should only have 1 Byte color information per channel. As i need to sum up in worst case 81 (smaller 128=7bit) pixel values, i thought the short as a target value would be great.

Any help concerning the right way to get simple access to the 8 bit values and use them in 16bit arrays would be great.

Thank you.


reinterpret_cast and use with CV_MAT_ELEM
===

i want to put all the data of an 8 bit input colorimage (Inputfile is a.bmp file)
in a new 16 bit Mat Array.

I do this because i need to sum up several image patches and then build the meanvalue for each pixel.

    Mat img = imread(Inputfile);   //there now should be values between 0 and 255 

Addressing the blue value for example like follows 

    uchar* ptr = img.data + img.step*row;
    cout << ptr[n*col] << endl;
    

only brings up single Letters and no values.

    cout << static_cast<short>(ptr[n*col]) << endl;

Typecasting to short or bigger brings up the correct values. but a cast to unsigned char (which is the correct datatype in my opinion) brings up the same Letters than without any typecast.


Short has 2 Bytes as i know, but a color .bmp should only have 1 Byte color information per channel. As i need to sum up in worst case 81 (smaller 128=7bit) pixel values, i thought the short as a target value would be great.

Any help concerning the right way to get simple access to the 8 bit values and use them in 16bit arrays would be great.

Thank you.

