Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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