Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - could not find encoder for the specified extension

Tags:

c++

opencv

Here is my code I am using to convert *IplImage to jpg:

IplImage* fIplImageHeader;
fIplImageHeader = cvCreateImageHeader(cvSize(160, 120), 8, 3);
fIplImageHeader->imageData = (char*) memblock;

vector<int> p;
p.push_back(CV_IMWRITE_JPEG_QUALITY);
p.push_back(10);
vector<unsigned char> buf;
cv::imencode("JPEG", fIplImageHeader, buf, p);

cvReleaseImageHeader(&fIplImageHeader);

But I am getting this error:

OpenCV Error: Unspecified error (could not find encoder for the specified extension) in imencode, file /build/buildd/opencv-2.1.0/src/highgui/loadsave.cpp, line 409

terminate called after throwing an instance of 'cv::Exception' what(): /build/buildd/opencv-2.1.0/src/highgui/loadsave.cpp:409: error: (-2) could not find encoder for the specified extension in function imencode

Why is that? I have OpenCV 2.1 installed. And this works so obviously jpg encoder must be there:

cvSaveImage("/home/richard/im.jpg", fIplImageHeader);
like image 587
Richard Knop Avatar asked Nov 23 '10 09:11

Richard Knop


1 Answers

Ok. I've figured this out. This works:

cv::imencode(".jpg", fIplImageHeader, buf, p);

They should mention it somewhere in the documentation that there should be a full stop before extension.

like image 119
Richard Knop Avatar answered Oct 13 '22 16:10

Richard Knop