Buffer to Mat [closed]

asked 2016-10-12 05:05:45 -0600

TiBe gravatar image

Hello guys,

I need your help.

I work with two cameras with a resolution of 4000x3000. Because of USB3 Vision I can only access with the manufacturer api on pictures.

As return value I get a pointer

void*                    BufferCam = NULL;
Strm_ReadCurrentImage(mStrmCam, BufferCam, &uiPyldSize, &sImageInfo);

Now I want to write the data into a cv Mat like this

Mat mCam= Mat(3000, 4000, CV_8UC3, BufferCam, Mat::AUTO_STEP);

Unfortunately my matrix keep empty. If I change size of the rows and cols like this

Mat mCam= Mat(1080, 1920, CV_8UC3, BufferCam, Mat::AUTO_STEP);

it work, but the image is understandably garbage.

image description

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2016-10-12 06:49:55.304447

Comments

can you try to find out the pixel format of your original buffer ? maybe CV_8UC3 is not adequate here.

also, be very cautious with constructors like above (shallow pointer copy), you eithere have to keep your original buffer in scope, or make a clone() of your Mat.

berak gravatar imageberak ( 2016-10-12 05:28:16 -0600 )edit

These are the image information I get from the function.

Or do you mean something different?

image description

TiBe gravatar imageTiBe ( 2016-10-12 05:54:19 -0600 )edit

3000 x 4000 = 12000000 - so i'd rather guess it's either grayscale (CV_8U) or something like yuv4:2:2 (which also would fit into a single byte)

also, please look up your vendor's documentation, what do they say about it ?

berak gravatar imageberak ( 2016-10-12 06:01:41 -0600 )edit
1

About the PixelFormat I found the following

https://secure.toshiba-teli.co.jp/ttf...

According to api the Pixel Format is BayerGR8

TiBe gravatar imageTiBe ( 2016-10-12 06:11:11 -0600 )edit

^^ yea, that was actually very helpful !

looking at your screenshot again, and the uiPixelFormat :

17301512 == 0x1080008, so it's BayerGR8 (oh, dear, that'll be fun unrolling)

berak gravatar imageberak ( 2016-10-12 06:16:50 -0600 )edit
  • make a Mat bayer(3000,4000,CV_8U, buffer), then
  • cvtColor(bayer, bgr, COLOR_BayerGR2BGR );
  • pray ;)
berak gravatar imageberak ( 2016-10-12 06:23:26 -0600 )edit
1

Is working. Thank you very much :)

TiBe gravatar imageTiBe ( 2016-10-12 06:33:34 -0600 )edit