Ask Your Question
1

How convert blob/binary data to Mat

asked 2013-08-10 03:44:47 -0500

redheli gravatar image

updated 2015-08-25 18:54:56 -0500

Hi,

I get a block of data from socket, which is a image. I can save this data to a file, like image.png. it shows picture instant in the folder.

the problem is : how can I convert this blob or brinary data to Mat format? I tried below code. but not work. as I don't know the col and row of the image.(each time the image size if different)

Mat image;
image.create( rows, cols, CV_16UC1 );
memcpy( image.data, blob_data, blob_data_length );

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2013-08-10 04:31:23 -0500

berak gravatar image

the method you're trying, should work fine with plain, uncompressed pixels.

what you get from the socket instead(is that mjpg or such ?) is probably a whole image, header, exif data, compressed pixels, etc.

read it into a std::vector, and feed that into imdecode instead

edit flag offensive delete link more

Comments

berak, You save my day! imdecode works like a charm. Thank you. The data block is a png format image. The final code likes below: std::vector<char> buffer(blob_data,blob_data+len); Mat img = imdecode(buffer,1);

redheli gravatar imageredheli ( 2013-08-10 05:11:20 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-08-10 03:44:47 -0500

Seen: 2,017 times

Last updated: Aug 10 '13