OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在Linux、Windows、Android和Mac OS操作系统上。 它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python、Ruby、MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算法。
今天在树莓派上搭建OPENCV环境:
1.安装numpy
sudo pip3 instal
2. 安装OpenCV所需的依赖
sudo apt-get install build-essential git cmake pkg-config -y
sudo apt-get install libjpeg8-dev -y
sudo apt-get install libtiff5-dev -y
sudo apt-get install libjasper-dev -y
sudo apt-get install libpng12-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt-get install libgtk2.0-dev -y
sudo apt-get install libatlas-base-dev gfortran -y
3.下载OpenCV
可以github上下载,也可以下载压缩包;
本次安装的OpenCV版本为OpenCV 4.4.0,官方链接地址
需要下载包括OpenCV与OpenCV_Contrib两个仓库
OpenCV_4.4.0仓库:Github地址
4.配置cmake;Cmake是一款跨平台的编译工具,经过配置,可输出适配于树莓派平台的Makefile
在opencv-4.4.0目录下新建一个build文件夹
然后进入文件夹
然后camke
cd/opencv-4.4.0
mkdir build
cd build
cmake .
5.没有出错,直接make
注意:make编译时间比较长,一般编译时间在5小时左右。
6.安装
sudo make insall
7.测试安装;
首先进入源码的示例文件夹中:opencv-4.4.0/samples/cpp/example_cmake
然后cmake 和make
pi@raspberrypi:~/Public/opencv-4.4.0/samples/cpp/example_cmake $ sudo cmake .
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- 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
-- Detecting C compile features
-- Detecting C compile features - done
-- 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
-- Found OpenCV: /usr/local (found version "4.4.0")
-- OpenCV library status:
-- config: /usr/local/lib/cmake/opencv4
-- version: 4.4.0
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio
-- include path: /usr/local/include/opencv4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/Public/opencv-4.4.0/samples/cpp/example_cmake
pi@raspberrypi:~/Public/opencv-4.4.0/samples/cpp/example_cmake $ sudo make
Scanning dependencies of target opencv_example
[ 50%] Building CXX object CMakeFiles/opencv_example.dir/example.cpp.o
[100%] Linking CXX executable opencv_example
[100%] Built target opencv_example
pi@raspberrypi:~/Public/opencv-4.4.0/samples/cpp/example_cmake $ sudo ./opencv_example
最后执行后弹出摄像头的界面,说明安装没有问题,如下图: