Ask Your Question
0

Convert RGBA byte buffer to OpenCV image?

asked 2013-01-29 21:28:36 -0600

Philip gravatar image

updated 2013-11-13 17:22:08 -0600

I have a byte buffer ( unsigned char * ) of RGBA format, I wish to use this image data in OpenCV, use it as a IplImage. How to convert from this byte buffer to IplImage?

Think I have worked this out myself, still testing.

IplImage* img = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 4);
cvSetData(img, buffer, width*4);
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2013-01-29 23:13:59 -0600

You have to cvCreateImageHeader instead of cvCreateImage

unsigned char* buffer;
int width = 100;
int height = 100;
IplImage* img1 =    cvCreateImageHeader(cvSize(width,height),IPL_DEPTH_8U,4);
cvSetData(img1,buffer,img1->widthStep);
edit flag offensive delete link more

Comments

Can you tell me why?

Philip gravatar imagePhilip ( 2013-01-30 08:58:52 -0600 )edit

Because the data is there and you need to create header for data instead of create image.

Mostafa Sataki gravatar imageMostafa Sataki ( 2013-01-30 09:16:44 -0600 )edit

Question Tools

Stats

Asked: 2013-01-29 21:28:36 -0600

Seen: 6,670 times

Last updated: Jan 29 '13