博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Opencv C++人脸识别
阅读量:3905 次
发布时间:2019-05-23

本文共 1371 字,大约阅读时间需要 4 分钟。

#include
using namespace std;using namespace cv;string Path = "C:\\Users\\hl\\Desktop\\haarcascade_frontalface_default.xml";int main(){
Mat img = imread("C:\\Users\\hl\\Desktop\\功能照片\\本科入学照片hl.jpg"); imshow("input image", img); CascadeClassifier Classifier;//定义分类器 Classifier.load(Path); if (!Classifier.load(Path)) //加载训练文件 {
cout << "xml文件加载失败" << endl; return -1; } VideoCapture capture(0); vector
faces; Classifier.detectMultiScale(img, faces, 1.1, 3, 0, Size(30, 30)); for (size_t t = 0; t < faces.size(); t++) {
rectangle(img, faces[t], Scalar(0, 255, 0), 2, 8);//画个绿框 } imshow("Result", img); waitKey(); return 0;}

image

当然有了图片的识别,视频就逐帧处理就好了。直接捕获电脑自带的摄像头就OK

#include
using namespace std;using namespace cv;string Path = "C:\\Users\\hl\\Desktop\\haarcascade_frontalface_default.xml";int main(){
CascadeClassifier Classifier;//定义分类器 Classifier.load(Path); if (!Classifier.load(Path)) //加载xml文件 {
cout << "xml文件加载失败" << endl; return -1; } VideoCapture capture(0);//捕获摄像头 vector
faces; while (true) {
Mat frame; capture >> frame;//逐帧处理 Classifier.detectMultiScale(frame, faces, 1.1, 3, 0, Size(30, 30)); for (size_t t = 0; t < faces.size(); t++) {
rectangle(frame, faces[t], Scalar(0, 255, 0), 2, 8);//画个绿框 } imshow("Result", frame); waitKey(10);//延时10ms } return 0;}

视频截图。

视频捕获

转载地址:http://mamen.baihongyu.com/

你可能感兴趣的文章
Relational Database Management System(RDBMS) basic
查看>>
deque
查看>>
Python threading operation
查看>>
Producer consumer model
查看>>
Python Tornado 异步和非阻塞I/O
查看>>
Python异步并发框架
查看>>
Python greenlet
查看>>
协程和多任务调度
查看>>
Python 协程与多任务调度
查看>>
Python yield coroutine
查看>>
Python IO multiplex
查看>>
Python RabbitMQ.Redis,Memcache
查看>>
Select, poll, epoll
查看>>
PHP session storage
查看>>
Redis + Django Session Cookie
查看>>
REST and RPC
查看>>
Web Architecture Basic idea
查看>>
Session & Cookie
查看>>
count lines in a file - wc & nl
查看>>
View the start/end of a file linux
查看>>