Ask Your Question

imencode & imdecode in iOS

asked 2012-12-02 15:24:45 -0600

asquared gravatar image

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(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.



edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-12-02 20:51:47 -0600

kevin gravatar image

Does the error have something to do with jpeg? Do you need to link to libjpeg maybe? I haven't really done any iOS programming, so not sure if that lib is already included.

edit flag offensive delete link more


I checked the libraries, but no luck. libjpeg is already included.

asquared gravatar imageasquared ( 2012-12-09 21:34:43 -0600 )edit

answered 2013-01-02 12:50:19 -0600

spr gravatar image

The problem is that the OpenCV framework doesn't build support for libjpeg. To fix this problem I had to build the framework myself (using these instructions) and modifying the root CMakeLists.txt with the following (about line 126):

OCV_OPTION(WITH_JPEG           "Include JPEG support"                           ON   IF IOS)

After that I still had to manually include libjpeg.a into my Xcode project, but imencode works again.

edit flag offensive delete link more

Question Tools


Asked: 2012-12-02 15:24:45 -0600

Seen: 4,972 times

Last updated: Jan 02 '13