预处理优化——cmake 编译opencv-3.4.3与libjpeg-turbo-2.0.1库

       opencv底层默认使用libjpeg做图像解码,libjpeg-turbo也是一种JPEG图像编解码器,解码速度通常是libjpeg的2-6倍,在条件相同的系统上,libjpeg-turbo可以在很大程度上优于libjpeg,这得益于其高度优化的Huffman编码。libjpeg-turbo的性能可以与专有的高速JPEG编解码器媲美,多线程的libjpeg-turbo解码速度与GPU加速的Nvidia nvJPEG硬解码相当。

       opencv3.4.3下3rdparty下自带libjpeg和libjpeg-turbo库,可通过cmakelist选择编译,默认为libjpeg。即使选择libjpeg-turbo,效率也不是很高,可能该版本较老。另外下载编译最新的libjpeg-turbo-2.0.1库。编译libjpeg-turbo-2.0.1与编译libjpeg-turbo-1.5.6之前的库方式不同,本文做下记录。

 

1、编译cmake

https://cmake.org/download/

下载最新的cmake-3.13.2.tar.gz

tar -xf cmake-3.13.2.tar.gz

cd  cmake-3.13.2

sudo ./bootstrap

sudo make -j12
 
sudo make install

2、编译libjpeg-turbo-2.0.1

https://sourceforge.net/projects/libjpeg-turbo/

下载最新的libjpeg-turbo-2.0.1

apt-get install nasm

cd libjpeg-turbo-2.0.1

mkdir build

cd build

cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RELEASE  -DENABLE_STATIC=FALSE  -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/libjpeg-turbo-2.0.1  -DCMAKE_INSTALL_DEFAULT_LIBDIR=lib  ..

make -j12

rm -f /usr/lib/libjpeg.so*

make install

3、编译opencv

修改cmakelist.txt

修改CMAKE_INSTALL_PREFIX到安装目录下,避免opencv多版本冲突
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")

打开BUILD_JPEG开关 
OCV_OPTION(BUILD_JPEG               "Build libjpeg from source"          ON)


后续测试cuda 预处理,打开CUDA开关
OCV_OPTION(WITH_CUDA           "Include NVidia Cuda Runtime support"                                         ON )

OCV_OPTION(BUILD_CUDA_STUBS         "Build CUDA modules stubs when no CUDA SDK" ON )

末尾增加message信息
message("****${JPEG_LIBRARY}")

修改cmake/OpenCVFindLibsGrfmt.cmake

通过JPEG_FOUND、BUILD_JPEG_TURBO_DISABLE选择解码库

# --- libjpeg (optional) ---
if(WITH_JPEG)
#  if(BUILD_JPEG)
#    ocv_clear_vars(JPEG_FOUND)
#  else()
#    include(FindJPEG)
#  endif()

  set(JPEG_FOUND ON)
  set(BUILD_JPEG_TURBO_DISABLE ON)

  if(NOT JPEG_FOUND)
    ocv_clear_vars(JPEG_LIBRARY JPEG_LIBRARIES JPEG_INCLUDE_DIR)

    if(NOT BUILD_JPEG_TURBO_DISABLE)
      set(JPEG_LIBRARY libjpeg-turbo)
      set(JPEG_LIBRARIES ${JPEG_LIBRARY})
      add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libjpeg-turbo")
      set(JPEG_INCLUDE_DIR "${${JPEG_LIBRARY}_SOURCE_DIR}/src")
      set(JPEG_TYPE "libjpeg-turbo")
    else()
      message("********libjpeg")
      set(JPEG_LIBRARY libjpeg)
      set(JPEG_LIBRARIES ${JPEG_LIBRARY})
      add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libjpeg")
      set(JPEG_INCLUDE_DIR "${${JPEG_LIBRARY}_SOURCE_DIR}")
      set(JPEG_TYPE "libjpeg")
    endif()
  endif()
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=../install  -DWITH_JPEG=ON -DBUILD_JPEG=OFF -DJPEG_INCLUDE_DIR=/home/libjpeg-turbo-2.0.1 -DJPEG_LIBRARY=/home/libjpeg-turbo-2.0.1/build/libturbojpeg.so ..

通过最后的message("****${JPEG_LIBRARY}")信息查看是否编的libjpeg-turbo-2.0.1.so

make -j12

make install

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值