13

I am using OpenCV 2.3.1 on OS X Lion in one of my C++ projects. While my project works great as-is, it depends heavily on JPEG decoding and encoding. I would like to gain a speedup by using libjpeg-turbo, but I cannot find the correct way to link with libjpeg-turbo. Depending on my hackery attempts and which files I edit, I either end up with compiling errors or with a useless OpenCV library (everything compiles correctly, but I cannot open or write JPEG files, though no errors appear in the C++ project).

Can anyone explain how you can compile OpenCV with libjpeg-turbo for faster JPEG decoding/encoding?

kvaruni
  • 832
  • 1
  • 10
  • 20

2 Answers2

24

To build OpenCV 2.4.0 with libjpeg-turbo you need:

  1. build libjpeg-turbo as a static library
  2. configure OpenCV with the following command:

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

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • 2
    OpenCV 2.3.1 can not be build with libjpeg-turbo without the source modification. – Andrey Kamaev May 05 '12 at 20:30
  • Thank you and my apologies for the late reply. While it did not work at first, this was mainly due to user error. Overall execution time is down by nearly 30% and opening and writing the actual JPEG file has seen a whopping 50%+ improvement. – kvaruni May 10 '12 at 08:15
10

OpenCV now has replaced libjpeg completely by libjpeg-turbo: https://github.com/opencv/opencv/pull/11497

It is in the current master and will be available in the upcoming 3.4.2

PhilLab
  • 4,777
  • 1
  • 25
  • 77
  • 1
    Finally. If you want to check what OpenCV is using then use the cv::getBuildInformation() call. From python import cv2 print cv2.getBuildInformation() In the output you should see some reference to libjpeg-turbo if this is in use. – D Dowling Nov 14 '18 at 11:45