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

lyl@ubuntu:~/桌面/aip-cpp-sdk-4.16.5$ sudo apt-get install libssl-dev正在读取软件包列表... 完成正在分析软件包的依赖关系树正在读取状态信息... 完成建议安装:libssl-doc下列【新】软件包将被安装:libssl-dev升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 246 个软件包未被升级 。需要下载 1,584 kB 的归档 。解压缩后会消耗 8,010 kB 的额外空间 。获取:1 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 libssl-dev amd64 1.1.1f-1ubuntu2.19 [1,584 kB]已下载 1,584 kB,耗时 4秒 (404 kB/s)正在选中未选择的软件包 libssl-dev:amd64 。(正在读取数据库 ... 系统当前共安装有 173613 个文件和目录 。)准备解压 .../libssl-dev_1.1.1f-1ubuntu2.19_amd64.deb...正在解压 libssl-dev:amd64 (1.1.1f-1ubuntu2.19) ...正在设置 libssl-dev:amd64 (1.1.1f-1ubuntu2.19) ...lyl@ubuntu:~/桌面/aip-cpp-sdk-4.16.5$ dpkg -s libssl-devPackage: libssl-devStatus: install ok installedPriority: optionalSection: libdevelInstalled-Size: 7822Maintainer: Ubuntu Developers Architecture: amd64Multi-Arch: sameSource: opensslVersion: 1.1.1f-1ubuntu2.19Depends: libssl1.1 (= 1.1.1f-1ubuntu2.19)Suggests: libssl-docConflicts: libssl1.0-devDescription: Secure Sockets Layer toolkit - development filesThis package is part of the OpenSSL project's implementation of the SSLand TLS cryptographic protocols for secure communication over theInternet..It contains development libraries, header files, and manpages for libssland libcrypto.Homepage: https://www.openssl.org/Original-Maintainer: Debian OpenSSL Team
3. 引入SDK头文件"face.h"
源代码中添加# "face.h"、usingaip; 。将base/http.h第23行的 # 换成 #。将base/base.h第21行的 # 换成 #。此时应该可以正常编译 。
//终端编译指令/g++ main.cpp -o main -std=c++11 -lopencv_videoio -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_objdetect -lopencv_imgcodecs -lcurl -lcrypto -ljsoncpp//cpp源代码/#include #include "opencv2/opencv.hpp"#include "face.h"using namespace std;using namespace cv;using namespace aip;int main() {// 打开摄像头//VideoCapture cap(0);VideoCapture cap(0, cv::CAP_V4L2);// 打开(默认的)摄像头0(编译时加上-lopencv_videoio)if(!cap.isOpened()) {// 检查摄像头是否成功打开cout << "Camera open failed!" << endl;return -1;}cout << "Camera open success." << endl;/显示视频-开始/Mat img_color; // 定义彩色图像(注意因为用到了mat,所以编译时加上-lopencv_core)Mat img_gray;// 定义灰度图Mat img_eql;// 定义直方图均衡化后的灰度图// 加载人脸的模型文件(-lopencv_objdetect)CascadeClassifier Classifier("/usr/share/opencv4/haarcascades/haarcascade_frontalface_alt2.xml");vector face_all; // 存储所有脸的方框列表Mat img_face_shot;// 存储人脸截图vector img_face_jpg; // 存储.jpg格式的人脸截图for(;;) {cap >> img_color;// 1.获取一帧彩色图像cvtColor(img_color, img_gray, cv::COLOR_BGR2GRAY);// 2.将彩图转换成灰度图(-lopencv_imgproc)equalizeHist(img_gray, img_eql);// 3.直方图均衡化(-lopencv_imgproc)Classifier.detectMultiScale(img_eql, face_all);// 4.人脸检测if(face_all.size()) {// 5.框出所有的人脸for(int i=0; i
下面是我在开发过程中的终端实际操作: