Ask Your Question
0

OpenCV 3.2 build for iOS with libjpeg-turbo to be used with Qt

asked 2017-01-04 16:28:57 -0600

hubaiz gravatar image

updated 2017-01-04 16:44:38 -0600

berak gravatar image

How to build OpenCV 3.2 with libjpeg-turbo for iOS so that it can be used with Qt (5.7.1 or 5.8) and avoid the JPEG version mismatch error and crash. I was using the following with 2.4

cmake -DWITH_JPEG=ON -DBUILD_JPEG=OFF -DJPEG_INCLUDE_DIR=/path/to/libjepeg-turbo/include/ -DJPEG_LIBRARY=/path/to/libjpeg-turbo/lib/libjpeg.a /path/to/OpenCV

and this worked, but fails with 3.2. If I use the 'OpenCV for iOS' with Qt and try to load a jpeg file with imdecode the application will crash with a jpeg version mismatch error.

Eventually is there other workaround for this?

Qt 5.7.1

#define JVERSION    "8c  16-Jan-2011"

OpenCV 3.2

#define JVERSION    "9  13-Jan-2013"
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-02-13 03:17:10 -0600

Ben Lau gravatar image

updated 2017-02-13 03:17:42 -0600

I have tried to build OpenCV 3.2 with libjpeg-turbo 1.3.0. It crashes in imwrite without any error message. Then I fallback to the libjpeg version used by Qt 5.8. That works.

The build Instruction

1) Download opencv 3.2 and opencv contrib 3.2 and extract them:

$ ls opencv-3.2.0 opencv_contrib-3.2.0

2) Download libjpeg source code

Since I have already downloaded the Qt 5.8 source code, I simply use Qt's version.

3) Patch opencv-3.2.0/platforms/ios/build_framework.py

--- build_framework.py.orig 2017-02-13 11:12:14.000000000 +0800
+++ build_framework.py  2017-02-13 11:13:42.000000000 +0800
@@ -135,6 +135,7 @@
             cmakecmd.append("-DENABLE_NEON=ON")
         cmakecmd.append(self.opencv)
         cmakecmd.extend(cmakeargs)
+        cmakecmd.extend(["-DWITH_JPEG=ON", "-DBUILD_JPEG=OFF","-DJPEG_INCLUDE_DIR=/opt/libjpeg-turbo/include", "-DJPEG_LIBRARY=/opt/libjpeg-turbo/lib64/libjpeg.a"])
         execute(cmakecmd, cwd = builddir)
         # Clean and build
         clean_dir = os.path.join(builddir, "install")

You should change the parameter of -DJPEG_INCLUDE_DIR and -DJPEG_LIBRARY according to your environment

-DJPEG_INCLUDE_DIR = Path to the source code

e.g ~/qt-everywhere-opensource-src-5.8.0/qtbase/src/3rdparty/libjpeg

-DJPEG_LIBRARY = Path to the libqjpeg.a from Qt SDK

e.g ~/Qt/5.8/ios/plugins/imageformats/libqjpeg.a

4) Build

cd opencv-3.2.0
mkdir build
cd build
../platforms/ios/build_framework.py ios --contrib=../../opencv_contrib-3.2.0
edit flag offensive delete link more

Comments

Thanks for the solution. Compiled OpenCV 3.2 with the Qt JPG library and now it works. :)

hubaiz gravatar imagehubaiz ( 2017-02-15 10:09:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-04 16:28:57 -0600

Seen: 1,431 times

Last updated: Feb 13 '17