opencv2与3编译安装

To install OpenCV 3.2.0 on Ubuntu 16.04:

Required Packages:

$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Download OpenCV:

$ sudo apt-get install wget
$ wget -O opencv-3.2.0.tar.gz https://github.com/opencv/opencv/archive/3.2.0.tar.gz
$ wget -O ippicv_linux_20151201.tgz https://raw.githubusercontent.com/opencv/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz

Install OpenCV:

$ sudo apt-get install tar
$ tar xf opencv-3.2.0.tar.gz
$ mkdir -p opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
$ cp ippicv_linux_20151201.tgz opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz
$ cd opencv-3.2.0
$ mkdir build
$ cd build

//不安装
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv320 ..
//安装
CPU(now):
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv320 -D OPENCV_EXTRA_MODULES_PATH=/home/montafan/software_download/opencv_contrib-3.2.0/modules/ ..
GPU:
$ cmake   -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local/opencv320   -D WITH_TBB=ON   -D WITH_V4L=ON   -D WITH_QT=ON   -D WITH_OPENGL=ON   -D WITH_CUDA=ON   -D ENABLE_FAST_MATH=1   -D CUDA_FAST_MATH=1   -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES"   -D WITH_CUBLAS=1 ..

$ make -j7
$ sudo make install


References:
    http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
    http://www.linuxfromscratch.org/blfs/view/cvs/general/opencv.html



安装完成后,写入opencv路径:(cp OpenCV.conf(内容为/usr/local/opencv320/lib)到/etc/ld.so.conf.d)
sudo sh -c 'echo "/usr/local/opencv320/lib" > /etc/ld.so.conf.d/opencv.conf'

更新电脑配准
sudo ldconfig

查看sudo ldconfig -v
得到:
    libopencv_core.so.3.2 -> libopencv_core.so.3.2.0
    libopencv_core.so.2.4 -> libopencv_core.so.2.4.9
可以成功链接





============================================
2.4.13
============================================
头文件路径
/usr/local/opencv2.4.13/include/opencv
/usr/local/opencv2.4.13/include/opencv2



cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.13  -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF ..

CPU:
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.13 BUILD_NEW_PYTHON_SUPPORT=OFF -D WITH_OPENCL=OFF -D WITH_OPENMP=ON -D INSTALL_C_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=OFF -D WITH_OPENGL=OFF -D WITH_VTK=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF ..

GPU:(https://developer.nvidia.com/cuda-gpus)  (WITH_OPENGL=ON)
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.13 -DCUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so -D CUDA_ARCH_BIN=5.0 -D CUDA_ARCH_PTX="" -D WITH_CUDA=ON -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_NVCUVID:BOOL="1" ..

复制:(关键)
sudo cp /usr/local/opencv2.4.13/lib/pkgconfig/opencv.pc  /usr/local/lib/pkgconfig
#cp /usr/local/opencv2.4.13/lib/pkgconfig/opencv.pc  /usr/lib/pkgconfig


执行:
sudo sh -c 'echo "/usr/local/opencv2.4.13/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
查看sudo ldconfig -v


sudo gedit ~/.bashrc
添加
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig  
export LD_LIBRARY_PATH=/usr/local/opencv2.4.13/lib
保存之后,再使用命令:
source ~/.bashrc  



例子
/software_download/opencv-2.4.13/samples/c/build.sh
====================================================================

























安装二维码生成qrencode:
./configure --prefix=/usr/local/libqrencode --without-tools
make
make install




写入路径:
opencv:
sudo sh -c 'echo "/usr/local/opencv320/lib" > /etc/ld.so.conf.d/opencv.conf'
pylon:
sudo sh -c 'echo "/opt/pylon5/lib64" > /etc/ld.so.conf.d/pylon5.conf'
zbar:
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/zbar.conf'
qrencode
sudo sh -c 'echo "/usr/local/libqrencode/lib" > /etc/ld.so.conf.d/qrencode.conf'

sudo apt-get install libmagick++-dev














OpenCV include path:/usr/local/opencv320/include/usr/local/opencv320/include/opencv
OpenCV lib path:opencv_calib3dopencv_coreopencv_features2dopencv_flannopencv_highguiopencv_imgcodecsopencv_imgprocopencv_mlopencv_objdetectopencv_photoopencv_shapeopencv_stitchingopencv_superresopencv_videoopencv_videoioopencv_videostabopencv_viz




OpenCV include path:/usr/local/opencv2.4.13/include/opencv/usr/local/opencv2.4.13/include
OpenCV lib path:opencv_videostabopencv_videoopencv_tsopencv_superresopencv_stitchingopencv_photoopencv_objdetectopencv_nonfreeopencv_mlopencv_legacyopencv_imgprocopencv_highguiopencv_flannopencv_features2dopencv_coreopencv_contribopencv_calib3d



PCL:
cmake -DCMAKE_BUILD_TYPE=None \
           -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON \
           -DCMAKE_INSTALL_PREFIX=/usr ..














切换opencv版本:

0.
   sudo sh -c 'echo "/usr/local/opencv320/lib" > /etc/ld.so.conf.d/opencv.conf'
   or
   sudo sh -c 'echo "/usr/local/opencv2.4.13/lib" > /etc/ld.so.conf.d/opencv.conf'
   sudo ldconfig

1、打开文件:

   sudo gedit ~/.bashrc

2、在文件末尾添加以下内容,然后保存:

   export PKG_CONFIG_PATH=/usr/local/opencv-3.2.0/lib/pkgconfig  
   export LD_LIBRARY_PATH=/usr/local/opencv-3.2.0/lib  

3、输入命令:

   source ~/.bashrc  

4、继续输入

   pkg-config --modversion opencv  
   pkg-config --cflags opencv  
   pkg-config --libs opencv  

以上步骤完成,即为替换完成,如果想从opencv-3.2.0切换回去,步骤同上。





问题:/usr/bin/ld: 找不到 -lopencv_dep_cudart
You have to add "set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)" in CMakeLists.txt,
or code in shell as this : cmake -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF


问题:
unsupported/Eigen/MatrixFunctions: 没有那个文件或目录
原因:两个Eigen
ln -s /usr/local/include/eigen3/unsupported /usr/local/include/
或者卸载一个Eigen
sudo apt-get remove --purge libeigen3-dev




opencv3.2下编译找不到libcudart.so:
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/lib/libcudart.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/lib/libcublas.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/lib/libcurand.so.8.0 && sudo ldconfig


CUDA_USE_STATIC_CUDA_RUNTIME=OFF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值