Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imencode & imdecode in iOS

Hi All,

I am trying to use OpenCV-2.4.3 in my iOS program. However, I have some issues with encoding and decoding the cv::Mat data structures. Here is the code below:

- (void) processImage:(cv::Mat&)image {
     /** processImage is a callback function, which is called for every frame captured by the camera. */
      vector<int> param;
      vector<uchar> buff;
      param.push_back(CV_IMWRITE_JPEG_QUALITY); 
      param.push_back(40); /* jpeg quality */
      cv::Mat image_copy(cv::Size(WIDTH,HEIGHT), CV_8UC3, cv::Scalar(0));
      cv::Mat outputFrame(cv::Size(WIDTH,HEIGHT), CV_16UC3, cv::Scalar(0));

     cv::cvtColor(image, image_copy, CV_BGRA2BGR);
     cv::imencode(".jpg", image_copy, buff, param);

     NSLog(@"Size using jpg compression %d, ", (int) buff.size());

     cv::imdecode(cv::Mat(buff), CV_LOAD_IMAGE_COLOR, &outputFrame);

     /** Testing the encode and the decode functions. */
}

However, the code looks good to me, but I get the following error:

OpenCV Error: Unspecified error (could not find encoder for the specified extension) in imencode, file /Users/alexandershishkov/opencv2.4.3rc/opencv/modules/highgui/src/loadsave.cpp, line 415
libc++abi.dylib: terminate called throwing an exception

Now, I am not sure what to do? I am kinda stuck on the same error for a long time. I have recompiled the OpenCV library for the iOS, however I don't see the mistake I am doing.

Comments/Code?

Thanks