Ask Your Question
1

imencode & imdecode in iOS

asked Dec 2 '12

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

Preview: (hide)

2 answers

Sort by » oldest newest most voted
0

answered Dec 3 '12

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.

Preview: (hide)

Comments

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

asquared gravatar imageasquared (Dec 10 '12)edit
0

answered Jan 2 '13

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.

Preview: (hide)

Question Tools

Stats

Asked: Dec 2 '12

Seen: 5,559 times

Last updated: Jan 02 '13