一、安装相关软件包
- 安装相关软件包
打开终端,安装以下软件包
sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
1.1 运行第二个命令的时候,出现如下错误:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
根据提示,输入:
sudo apt-get update
完成后,再次输入第二个命令,就显示成功了。
1.2 运行第三个命令的时候,出现如下错误:
E: Unable to locate package libjasper-dev
参考这个文章,输入:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt upgrade
sudo apt install libjasper1 libjasper-dev
1)但是再输入第一个命令的时候,又出现如下:
-bash: add-apt-repository: command not found
参考这个文章,安装包:
sudo apt-get install software-properties-common
sudo apt-get update
显示Reading package lists... Done 成功了。 2)接着输入第二个命令,显示90 packages can be upgraded. Run 'apt list --upgradable' to see them. 3)输入第三个命令,显示:
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
参考这个文章,输入ps -e|grep apt-get 释放系统锁,但是什么都没有输出。 再次输入第三个命令,输出done. Processing triggers for initramfs-tools (0.130ubuntu3.13) ... 4)输入第四个命令,输出:
Processing triggers for libc-bin (2.27-3ubuntu1.5) ...
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 is not a symbolic link
没什么关系,包已经安装好了的。
二、获取Source
- 查看Ubuntu版本,可以参考这个连接。
- 根据对应的版本,从官网下载source包。
下载成功后解压。
三、安装OpenCV
- 进入解压出来的OpenCV-4.5.5 文件夹,创建一个新文件夹,命名为:build
- cd到build里,
cd /root/opencv-4.5.5/build - 输入:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. 输出:
-- Generating done
-- Build files have been written to: /root/opencv-4.5.5/build
完成。 4. 输入sudo make 报错,输出:
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFSetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFGetField@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFClose@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
../../lib/libopencv_imgcodecs.so.4.5.5: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
modules/core/CMakeFiles/opencv_test_core.dir/build.make:1350: recipe for target 'bin/opencv_test_core' failed
make[2]: *** [bin/opencv_test_core] Error 1
CMakeFiles/Makefile2:1197: recipe for target 'modules/core/CMakeFiles/opencv_test_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
4.1 参考这个,重新cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_SHARED_LIBS=OFF -D WITH_OPENMP=ON -D ENABLE_PRECOMPILED_HEADERS=OFF ..
然后make -j8 ,报错,在62%的时候,解决了前面其中一个问题。(看大家都说是在cmake步骤报错,但是我每次cmake都没问题,sudo make就报错。)
Linking CXX static library ../../lib/libopencv_dnn.a
[ 62%] Built target opencv_dnn
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
4.2 参考这个,再次重新cmake,
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_SHARED_LIBS=OFF -D WITH_OPENMP=ON -D ENABLE_PRECOMPILED_HEADERS=OFF -D BUILD_TIFF=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_GTK=ON -D WITH_OPENGL=ON ..
然后make -j8 ,报错,在86%的时候,
/root/opencv-4.5.5/samples/cpp/tutorial_code/gapi/doc_snippets/dynamic_graph_snippets.cpp:1:10: fatal error: opencv2/gapi.hpp: No such file or directory
^~~~~~~~~~~~~~~~~~
compilation terminated.
samples/cpp/CMakeFiles/example_tutorial_dynamic_graph_snippets.dir/build.make:62: recipe for target 'samples/cpp/CMakeFiles/example_tutorial_dynamic_graph_snippets.dir/tutorial_code/gapi/doc_snippets/dynamic_graph_snippets.cpp.o' failed
make[2]: *** [samples/cpp/CMakeFiles/example_tutorial_dynamic_graph_snippets.dir/tutorial_code/gapi/doc_snippets/dynamic_graph_snippets.cpp.o] Error 1
CMakeFiles/Makefile2:10720: recipe for target 'samples/cpp/CMakeFiles/example_tutorial_dynamic_graph_snippets.dir/all' failed
make[1]: *** [samples/cpp/CMakeFiles/example_tutorial_dynamic_graph_snippets.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
4.3 打开这个文件[/root/opencv4.5.5/samples/cpp/tutorial_code/gapi/doc_snippets/dynamic_graph_snippets.cpp],发现头文件#include <opencv2/gapi.hpp> , 待续。。。
|