【Ubuntu】基于C++实现人脸识别( 五 )


安装完了之后,可以查看一下的安装版本,可以看到,的安装版本是4.2.0+dfsg-5:
lyl@ubuntu:~/桌面$ dpkg -s libopencv-devPackage: libopencv-devStatus: install ok installedPriority: optionalSection: libdevelInstalled-Size: 399Maintainer: Ubuntu Developers Architecture: amd64Source: opencvVersion: 4.2.0+dfsg-5Replaces: libcv-dev, libcvaux-dev, libhighgui-devDepends: libopencv-calib3d-dev (= 4.2.0+dfsg-5), libopencv-contrib-dev (= 4.2.0+dfsg-5), libopencv-core-dev (= 4.2.0+dfsg-5), libopencv-dnn-dev (= 4.2.0+dfsg-5), libopencv-features2d-dev (= 4.2.0+dfsg-5), libopencv-flann-dev (= 4.2.0+dfsg-5), libopencv-highgui-dev (= 4.2.0+dfsg-5), libopencv-imgcodecs-dev (= 4.2.0+dfsg-5), libopencv-imgproc-dev (= 4.2.0+dfsg-5), libopencv-ml-dev (= 4.2.0+dfsg-5), libopencv-objdetect-dev (= 4.2.0+dfsg-5), libopencv-photo-dev (= 4.2.0+dfsg-5), libopencv-shape-dev (= 4.2.0+dfsg-5), libopencv-stitching-dev (= 4.2.0+dfsg-5), libopencv-superres-dev (= 4.2.0+dfsg-5), libopencv-ts-dev (= 4.2.0+dfsg-5), libopencv-video-dev (= 4.2.0+dfsg-5), libopencv-videoio-dev (= 4.2.0+dfsg-5), libopencv-videostab-dev (= 4.2.0+dfsg-5), libopencv-viz-dev (= 4.2.0+dfsg-5), libopencv4.2-java (= 4.2.0+dfsg-5), pkg-config, libc6 (>= 2.14), libgcc-s1 (>= 3.0), libopencv-calib3d4.2 (>= 4.2.0+dfsg), libopencv-contrib4.2 (>= 4.2.0+dfsg), libopencv-core4.2 (>= 4.2.0+dfsg), libopencv-features2d4.2 (>= 4.2.0+dfsg), libopencv-highgui4.2 (>= 4.2.0+dfsg), libopencv-imgcodecs4.2 (>= 4.2.0+dfsg), libopencv-imgproc4.2 (>= 4.2.0+dfsg), libopencv-videoio4.2 (>= 4.2.0+dfsg), libstdc++6 (>= 9), libilmbase-devRecommends: opencv-dataSuggests: opencv-docBreaks: libopencv-core-dev (<= 2.3.1-8)Conflicts: libcv-dev, libcvaux-dev, libhighgui-devDescription: development files for opencvThis is a metapackage providing development package necessary fordevelopment of OpenCV (Open Computer Vision)..The Open Computer Vision Library is a collection of algorithms and samplecode for various computer vision problems. The library is compatible withIPL (Intel's Image Processing Library) and, if available, can use IPP(Intel's Integrated Performance Primitives) for better performance..OpenCV provides low level portable data types and operators, and a setof high level functionalities for video acquisition, image processing andanalysis, structural analysis, motion analysis and object tracking, objectrecognition, camera calibration and 3D reconstruction.Original-Maintainer: Debian Science Team Homepage: https://opencv.org
图3-2 下载并打开帮助文档
在使用的过程中,需要有一些帮助文档来辅助进行开发:
官网的帮助文档:(本人体验是真的香~) 。
官网的帮助文档如果无法下载:
解压后直接在文件中打开“index.html”就可以直接查看帮助文档了 。
3.3 编程-图像采集(上)
上一节已经在中配置好了开发环境,本节就来打开摄像头 。首先需要将主机上的摄像头打开,并设置由虚拟机控制:“无法连接笔记本/电脑摄像头的解决方法”(注意自己的摄像头名称) 。然后使用指令ls /dev/查看/dev目录,若存在这个文件夹就说明摄像头添加成功 。
下面是打开摄像头的代码 。由于使用了.2.0中的“. High-level GUI and Media I/O”中的“”方法,所以编译时要加上-:
// 编译指令g++ main.cpp -o main -lopencv_highgui// 源代码#include #include "opencv2/opencv.hpp"// #include "opencv4/opencv2/opencv.hpp"// 建议用这一行,而不是上面一行using namespace std;using namespace cv;int main() {//VideoCapture cap(0);VideoCapture cap(0, cv::CAP_V4L2);// 打开(默认的)摄像头0if(!cap.isOpened()) {// 检查摄像头是否成功打开cout << "Camera open failed!" << endl;return -1;}cout << "Camera open success."