解决办法
cmake
make
....
[100%] Built target opencv_example
admin@ub:~/opencv/samples/cpp/example_cmake/build$ ./opencv_example
Built with OpenCV 4.6.0
Capture is opened
Gtk-Message: 09:56:19.551: Failed to load module "canberra-gtk-module"
sudo apt-get install libcanberra-gtk-module
./opencv_example
Built with OpenCV 4.6.0
Capture is opened
^C
成功!
这是黎明前最后个问题,故放在前面。
以下是查看 history 复盘 Ubuntu 20.04 install OpenCV 4.7.0后改为4.6.0。
个人总结,非保姆级教程,最新最详细看向日葵骑士Faraday原创的Ubuntu18.04安装Opencv4.5(最新最详细)。虽然我是中途参考,但获益良多。
自动与手动 an 装
标题很吸引,但自动与手动an装均未成功,事后发现一处错误,原帖(看这篇就够了——opencv与libopencv与cv_bridge的安装与使用)里验证opencv是否安装
pkg-config --modversion opencv
在我电脑上验证
admin@ub:~/opencv$ pkg-config --modversion opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
admin@ub:~/opencv$ pkg-config --modversion opencv4
4.6.0
这部分是失败的循环。
在linux中, ldd是list, dynamic, dependencies的缩写, 列出动态库依赖关系。
475 ./camera
476 cat ../README.md
477 ldd camera
478 sudo aptitude install opencv
479 locate libopencv_highgui
480 sudo find / -name "libopencv_highgui"
481 sudo aptitude install opencv
482 sudo aptitude install libopencv-highgui-dev
483 ./camera
484 ldd camera
485 sudo find / -name "libopencv_highgui"
486 su
487 sudo aptitude install python3
488 python3
489 ./camera
490 ldd camera
498 ./camera
499 sudo aptitude install libopencv-dev
505 sudo aptitude install ros-noetic-cv-bridge
506 ldd camera
507 ./camera
508 ldd camera
509 sudo find / -name "libopencv_core.406"
510 su
511 pkg-config --modversion opencv
512 sudo apt-get install libopencv-highgui-dev
523 ldd camera
524 ldd gtk2.0-dev
运行./camera 命令时,报错缺少libopencv_highgui.so.3.2,ldd 查看依赖。
admib@ub:~$ ldd camera
linux-vdso.so.1 (0x00007fff1fb4e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f419ad0c000)
libopencv_highgui.so.3.2 => not found
libopencv_videoio.so.3.2 => not found
libopencv_imgcodecs.so.3.2 => not found
libopencv_imgproc.so.3.2 => not found
libopencv_core.so.3.2 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f419a983000)
libcudart.so.9.0 => /usr/local/cuda-9.0/lib64/libcudart.so.9.0 (0x00007f419a716000)
libcublas.so.9.0 => /usr/local/cuda-9.0/lib64/libcublas.so.9.0 (0x00007f41972e0000)
libcurand.so.9.0 => /usr/local/cuda-9.0/lib64/libcurand.so.9.0 (0x00007f419337c000)
libcudnn.so.7 => /usr/local/cuda-9.0/lib64/libcudnn.so.7 (0x00007f41805f6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f41803de000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f41801bf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f417fdce000)
/lib64/ld-linux-x86-64.so.2 (0x00007f419b478000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f417fbca000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f417f9c2000)
以上代码选自问题解决:运行./darknet命令时,报错缺少libopencv_highgui.so.3.2包,不想折腾或首次an装看上文保姆教程。
官网教程
获取源码
OpenCV官网地址OpenCVReleases
OpenCVTutorials,注意Opencv的版本号。
Cmake 手动编译 Opencv
复习常用解压缩命令
tar -zcvf
tar -zxvf
gzip
gzip -d
zip
unzip
这部分是参考官网Quick start
Build core modules,Installation in Linux 。
# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
# Create build directory
mkdir -p build && cd build
# Configure
cmake ../opencv-4.x
# Build
cmake --build .
这部分官网教程不适合排查问题,可能一处错误后面无法进行。
526 cd ../../
527 ls
528 gzip opencv-4.7.0.zip
529 ls
530 gzip -d opencv-4.7.0.zip.gz
531 ls
532 zip -help
533 zip -A opencv-4.7.0.zip
534 unzip opencv-4.7.0.zip
535 ls
536 cd opencv-4.7.0/
537 ls
538 cd cmake/
539 ls
540 cd ../../
541 ls
542 mv opencv-4.7.0 /usr/local/
543 su
544 sudo aptitude install g++
545 cmake -v
546 sudo aptitude install cmake
547 wget
548 wget -v
549 cd /usr/lib
550 ls
551 cd ../local/
552 ls
553 cd opencv-4.7.0/
554 ls
555 mkdir build
556 ls
557 cd build/
558 cmake ../../opencv-4.7.0/
559 cd ../../
560 ls
561 mv opencv-4.7.0/build/ ./
562 su
563 ls
564 cmake --build ./
565 su
566 cd opencv-4.7.0/
567 ls
568 cmake --build ./
569 su
570 cd ../
571 ls
572 cmake build/ .
573 rm -rf build/
574 su
575 sudo aptitude update && sudo aptitude upgrade
576 cd opencv-4.7.0/samples/cpp/
577 ls
578 cd example_cmake/
579 ls
580 cd build/
581 ls
582 ./opencv_example
583 sudo aptitude install libgtk2.0-dev
584 cd ../../../
585 cd ../
586 ls
587 cd modules/
588 ls
589 cd highgui/src/
590 ls
591 cd ../../../
592 pip uninstall opencv-python
593 opencv-python
594 sudo aptitude install python3-pip
595 pip uninstall opencv-python
596 pip install opencv-contrib-python
597 pip uninstall opencv-python
598 sudo aptitude install libgtk2.0-dev
599 cd /etc/
600 ls
601 file apt/
602 cd apt/
603 ls
604 gedit sources.list
605 ls -l sources.list
重新编译链接 4.6.0
这部分发现一处错误,向日葵骑士Faraday原创的Ubuntu18.04安装Opencv4.5(最新最详细)
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D -D OPENCV_ENABLE_NONFREE=True ..
报错信息为
admin@ub:~/opencv/build$ cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D -D OPENCV_ENABLE_NONFREE=True ..
Parse error in command line argument: -D
Should be: VAR:type=value
CMake Error: No cmake script provided.
CMake Error: Problem processing arguments. Aborting.
admin@ub:~/opencv/build$ cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=True ..
-- The CXX compiler identification is GNU 9.4.0
-- The C compiler identification is GNU 9.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
.......
-- Configuring done
-- Generating done
-- Build files have been written to: .....
admin@ub:~/opencv/build$ sudo make -j12
经历漫长编译、链接后
606 su
607 cd ../
608 cd build/
609 rm -rf *
610 cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D -D OPENCV_ENABLE_NONFREE=True ..
611 cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=True ..
612 sudo make -j12
613 sudo make install
614 sudo gedit /etc/bash.bashrc
615 souce /etc/bash.bashrc
616 source /etc/bash.bashrc
617 #打开下列文件
618 sudo gedit /etc/ld.so.conf.d/opencv.conf
619 # 添加lib路經 在 末尾 保存退出
620 /usr/local/lib
621 # 更新
622 sudo ldconfig
623 pkg-config --modversion opencv4
624 pkg-config --libs opencv4
625 cd ../
626 cd samples/cpp/example_cmake/
627 mkdir build
628 cd build/
629 cmake ..
630 make
631 ./opencv_example
632 pwd
633 sudo apt-get install libcanberra-gtk-module
634 ls
635 ./opencv_example
636 history
以上。
标签:load,sudo,..,--,gtk,module,cd,opencv,ls From: https://www.cnblogs.com/funlab/p/17363407.html