First time here? Check out the FAQ!

Ask Your Question
0

Convert RGBA byte buffer to OpenCV image?

asked Jan 30 '13

Philip gravatar image

updated Nov 13 '13

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);
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Jan 30 '13

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);
Preview: (hide)

Comments

Can you tell me why?

Philip gravatar imagePhilip (Jan 30 '13)edit

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

Mostafa Sataki gravatar imageMostafa Sataki (Jan 30 '13)edit

Question Tools

Stats

Asked: Jan 30 '13

Seen: 6,929 times

Last updated: Jan 29 '13