如何检测网络摄像头并比较本地文件以匹配人脸 OpenCV
how can i detect webcam and compare the local file to match face OpenCV
突出显示的代码表明openCV框架已加载到我的C代码中,并且它呈现了警察监视。这只是为了证明它非常流畅且
编写的代码非常干净。目标:我的网络CAM已连接到USB端口。我想捕获实时网络摄像头图像并从本地文件(/tmp/myface.png)匹配,如果实时网络摄像头与本地文件 myface.png 匹配,它将显示文本"警察观看"
我现在如何在以下代码上捕获我的 webCAM? 2)捕获 webCAM 时,我如何加载文件并查找它是否匹配,在匹配时它仅显示该文本。
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <fstream>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
#include "opencv/cv.h"
void detectAndDisplay(Mat frame);
//*************
// Set Region of Interest
cv::Rect roi_b;
cv::Rect roi_c;
size_t ic = 0; // ic is index of current element
int ac = 0; // ac is area of current element
size_t ib = 0; // ib is index of biggest element
int ab = 0; // ab is area of biggest element
stringstream ssfn;
//*************
CascadeClassifier face_cascade;
string window_name = "Capture - Face detection";
int filenumber; // Number of file to be saved
string filename;
Mat frameread = imread("test.jpg");
int main(int argc, const char *argv[]){
if (argc != 4) {
cout << "usage: " << argv[0] << " </path/to/haar_cascade> </path/to/csv.ext> </path/to/device id>" << endl;
cout << "t </path/to/haar_cascade> -- Path to the Haar Cascade for face detection." << endl;
cout << "t </path/to/csv.ext> -- Path to the CSV file with the face database." << endl;
cout << "t <device id> -- The webcam device id to grab frames from." << endl;
// exit(1);
}
CascadeClassifier face_cascade;
CascadeClassifier face_cascade1;
String fn="C:\opencv\sources\data\haarcascades\haarcascade_frontalface_alt2.xml";
String fn1="C:\opencv\sources\data\haarcascades\haarcascade_eye.xml";
face_cascade.load(fn);
face_cascade1.load(fn1);
VideoCapture input(0);
if(!input.isOpened()){return -1;}
namedWindow("Mezo",1);
Mat f2;
Mat frame;
std::vector<Rect> faces,faces1;
CvCapture* capture1;
IplImage* f1;
Mat crop;
cv::Rect r;
// detectAndDisplay(frameread);
while(1)
{
ic=0;
ib=0;
ab=0;
ac=0;
input >> frame;
waitKey(10);
//cvtColor(frame, frame, CV_BGR2GRAY);
//cv::equalizeHist(frame,frame);
face_cascade.detectMultiScale(frame, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
for(int i=0; i < faces.size();i++)
{
Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
Point pt2(faces[i].x,faces[i].y);
Mat faceROI = frame(faces[i]);
face_cascade1.detectMultiScale(faceROI, faces1, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30,30));
for(size_t j=0; j< faces1.size(); j++)
{
Point center(faces[i].x+faces1[j].x+faces1[j].width*0.5, faces[i].y+faces1[j].y+faces1[j].height*0.5);
int radius = cvRound((faces1[j].width+faces1[j].height)*0.25);
circle(frame, center, radius, Scalar(255,0,0), 2, 8, 0);
}
rectangle(frame, pt1, pt2, cvScalar(0,255,0), 2, 8, 0);
}
imshow("Result", frame);
waitKey(3);
char c = waitKey(3);
if(c == 27)
break;
}
return 0;
}
你问的可能是人脸识别。你应该在你的问题中更清楚。
Opencv有一个完美识别的类,而不是像你想象的那样。
这项技术有很多方法可用,Opencv 有三种算法。此外,您还需要准备图像数据库(标记的人脸)
所有这些步骤都在opencv文档中进行了描述 http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html,并提供了一些示例:只是您需要阅读并申请。
在这里,您还可以找到适合初学者的好教程。
相关文章:
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- OpenCV 4.2.0 文件存储分段错误
- 加载"D:UsersPublicDocumentsopencvbuildx64vc14binopencv_world340d.dll",找不到或打开PDB文件
- OpenCV 3 Visual Studio 2017 调试,调用堆栈没有.pdb文件
- OpenCV 安装错误:没有这样的文件或目录"pyopencv_generated_include.h"
- 如何在Visual Studio中添加OpenCV文件
- 无法在 CLion 中编译 OpenCV 头文件
- 使用 Opencv 将姿势值实时写入文本文件
- 如果函数使用 OPENCV Mat 作为输入,如何编写头文件?
- OPENCV - 如何在OpenCV中使用Haar Cascade Github xml文件?
- CUDA opencv 构建失败 - 缺少实际存在的文件
- 在头文件中使用opencv类型来实现未定义的标识符
- 帧提取 使用OpenCV的视频文件开头只有几秒钟
- 从YML文件OPENCV C 初始化摄像机参数
- 从文件OpenCV读取视频
- 如何从XML文件(OpenCV)将一定数量的行读入Mat对象
- 将矢量<Mat>转换为矢量文件 Opencv
- 在Linux上构建opencv_controib示例可执行文件(opencv 3.0.0-alpha)
- BASH脚本编译多个c++文件- OpenCV
- 当对象靠近时将帧保存到文件 opencv.