Memory allocation in Mat for images - does it change type?

asked 2015-02-25 15:54:33 -0600

ClintFromVa gravatar image

Hi all,

I think I have this figured out but I'm interested in your perspective. I'm working in C++ under VS2013.

From the documentation on rotated rectangles there is this declaration:

    Mat image(200, 200, CV_8UC3, Scalar(0));

That looks like 200 x 200 pixels, 8-bit BRG color, with three color values passed in by the Scalar (Scalar being anything other than a simple number is a confusing offense unto Nuggin but is discussed elsewhere).

I wanted to check if the type casting really worked, storing 24 bits per pixel, or if the Scalar was still reserving four doubles for each. Finding (int)abs(image.datastart - image.dataend) resulted in 3 unsigned char per pixel ... which Microsoft says is a 1 byte type (MS VBA is 2 bytes for a char, go figure). So that all looks as expected, minimum space used and all is well.

Problem though, I think I read as I researched this that under some matrix arithmetic operations the data gets changed to type float. I guess I could see the utility in that but it seems like a gotcha too. Does that really happen? What is good practice here?

Thanks

edit retag flag offensive close merge delete

Comments

"MS VBA is 2 bytes for a char, go figure" - oh, you 're safe to ignore, how access basic stores text

berak gravatar imageberak ( 2015-02-26 07:08:39 -0600 )edit