OpenCV default storage format

What is the default (Pixel) storage format used by OpenCV ?

I know it is BGR but is it BGR32 ? BGR16 ? Is it Packed or Planar ?

Can you suggest me a way to find it out?

Thank you for your help.

[EDIT] Context : Actually I am trying to use OpenCV with another library called MIL (Matrox Imaging Library). I need to grab an Image with MIL and then convert it to an OpenCV Image. That is why I need to know the default pixel format, to configure MIL.


The image format is set by the flag when you create the image eg CV_8UC3 means 8bit pixels, unsigned, 3colour channels. In a colour image the pixel order is BGR, data is stored in row order.

The data isn't packed at the pixel level - it's 3bytes/pixel (BGRA is an option on some of the GPU calls).

Data may be packed at the line level, if the number of pixels in a row * the number of bytes/pixel isn't a multiple of 4 then the data is padded with zero to the next 32bit boundary. The call mat.ptr(n) returns a pointer to the start of the 'n' th row

Note that you can share memory with another comaptible image format by passing the data pointer from the MIL image to the ctor of the cv::Mat


It depends on the way you are managing the image: have you loaded it from a file with imread for example? Have a look at imread here, with a colour jpeg for example you'll have a 3 channel format, 24 bits overall. Can you be more specific?

I do not know if it's useful, but I had a similar issue when converting an image from Android Bitmap (passed to OpenCV as a byte array RGBA8888) to OpenCV image (BGR888). Here is how I've solved it.

cv::Mat orig_image1(orig_height, orig_width, CV_8UC4, image_data);   

int from_to[] = { 0, 2,  1, 1,  2, 0};    
cv::Mat image(orig_height, orig_width, CV_8UC3);   
cv::mixChannels(&orig_image1, 1, &image, 1, from_to, 3);
orig_image1.release();
链接地址: http://www.djcxy.com/p/89754.html

上一篇: 确定OpenCV中像素的平均距离(到图像的中心)

下一篇: OpenCV默认存储格式