how can i use a jpeg image with addon OPENCV

i have a buffer (640x480 jpeg image) which i would like to convert into ofxCvColorImage or ofxCvImage struct.

The buffer is: char sockdata[40000];
The struct is:
ofxCvColorImage colorImg;


colorImg.setFromPixels((unsigned char*)sockdata,640,480);  

oh, sorry, didn’t understood it’s jpeg not raw pixels:

ofPixels pixels;  
ofBuffer buffer(sockdata,size);  

thank you,
but i don’t find any ofBuffer and ofLoadImage structs
i am using the 0F 0062 , is this the problem?

yes 0062 is too old, you cannot load jpegs from memory before 007 i think

sorry, i have an old project in C :

CvMat matbox = cvMat(480, 640, CV_8UC1, sockdata);

IplImage img = cvDecodeImage(&matbox, 1);

cvShowImage(“figure”, img); //which shows the image.

The opencv guide states:

C++: Mat imdecode(InputArray buf, int flags)
C++: Mat imdecode(InputArray buf, int flags, Mat* dst)
C: IplImage* cvDecodeImage(const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)
C: CvMat* cvDecodeImageM(const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)

and parameters:
buf – Input array or vector of bytes.
flags – The same flags as in imread() .
dst – The optional output placeholder for the decoded matrix. It can save the image reallocations when the function is called repeatedly for images of the same size.

The function reads an image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the empty matrix/image is returned.

And now, i want to bring to OF, i could try to use the Mat struct, but the OF doesn’t recognized it.
So, the 1° instruction is ok. The problem is the second, i can’t use it with C++ with OF, i think.

Don’t you have the openCV c++ interface in your 0062 project? What is the error you’re getting? I use openCV from my own build, not the one that ships with OF, you can always link to an extern OpenCV build.

i can’t use this instruction in OF:
IplImage img = cvDecodeImage(&matbox, 1);

the “cvDecodeImage” is undefined in OF.

You’re right. I’ve already done just using opencv and it was ok, but now I need to do it in OF because my project needs to be added to a new project made ??by other people in OF. :confused:

In this moment, i am trying by using the FreeImage library (FreeImage.h) …working in progress…