当前位置:网站首页>Opencv does not rely on any third-party database for face detection
Opencv does not rely on any third-party database for face detection
2022-06-10 18:54:00 【QMCY_ jason】
design sketch :

Code section : It doesn't involve any complicated Machine learning library or something opencv A few simple api You can run , Simply do an introductory guide You can find The side face cannot be detected The face is basically detectable
void do_findface()
{
string xml_path = R"(E:\jason\software\opencv\opencv\build\etc\haarcascades\haarcascade_frontalface_alt2.xml)";// Similar to the model file opencv Self contained
string img_path = R"(E:/jason/5D4/multi2.png)"; // Pictures to be tested
Mat face_img = imread(img_path,IMREAD_COLOR); // Normal color map
Mat face_gray = imread(img_path,IMREAD_GRAYSCALE);// Open in grayscale mode
namedWindow("gray", WINDOW_NORMAL);
namedWindow("equalizeHist", WINDOW_NORMAL);
if (face_img.empty() || face_gray.empty())
{
cout<<"Load image failed" << endl;
}
imshow("gray", face_gray);
equalizeHist(face_gray,face_gray); // Histogram equalization Add comparison chart Do not do In this example, the effect is not significant More importantly, it affects the performance estimation
//imshow("equalizeHist", face_gray);
CascadeClassifier faceCascade;
if (!faceCascade.load(xml_path))
{
cout << "Load xml path failed :["<<xml_path<<"]" << endl;
return ;
}
vector<Rect>faces; // The detected face rectangle coordinates will be put here
faceCascade.detectMultiScale(face_gray,faces,1.2,5,0,Size(30,30));
int index = 0;
for (auto b:faces)
{
index++;
cout << "Face pos:[" << index << "][" << b.x << "," << b.y <<","<<b.width<<","<<b.height << "]" << endl;
}
if (faces.size() > 0)
{
for (size_t i = 0; i < faces.size(); i++)
{
putText(face_img,"face",Point(faces[i].x-10,faces[i].y-10), FONT_HERSHEY_COMPLEX_SMALL, 1.0, Scalar(0, 0, 255));
rectangle(face_img, Point(faces[i].x, faces[i].y), Point(faces[i].x+faces[i].width,faces[i].y+faces[i].height), Scalar(0, 255, 0), 2, 8);
cout << "faces:------------------>" << faces[i] << endl;
}
}
imshow("equalizeHist",face_img);
waitKey();
destroyAllWindows();
}
int main()
{
//do_filter();
//do_addweight();
//do_sharpen();
//do_cvtColor();
//do_findContours();
do_findface();
return 0;
}边栏推荐
- AD18器件库导入简介
- MySQL index invalidation scenario
- 5. golang generics and reflection
- VIM common shortcut keys
- 企业数据质量管理:如何进行数据质量评估?
- VMware vCenter version number comparison table
- Adobe Premiere基础-素材嵌套(制作抖音结尾头像动画)(九)
- 商业智能BI的价值,可视化报表等于商业智能BI吗?
- 3. getting started with golang concurrency
- Adobe Premiere Foundation (the last step of video subtitle adding) (6)
猜你喜欢

Wechat applet, get the current page and judge whether the current page is a tabbar page

Data URL

商业智能BI如何帮企业降低人力、时间和管理成本?

Adobe Premiere Foundation (animation production - Flexible animation) (VIII)

什么是商业智能BI,谈谈商业智能BI的定义与作用

“数字化转型,数据先行”,谈谈数据治理对企业来说到底有多重要

Adobe Premiere foundation - opacity (matte) (11)

The value of Bi in the enterprise: business analysis and development decision

Adobe Premiere foundation - material nesting (animation of Tiktok ending avatar) (IX)

Adobe Premiere foundation - tool use (selection tool, razor tool, and other common tools) (III)
随机推荐
Db2 SQL PL中的控制语句
Adobe Premiere基础-导入导出,合并素材,源文件编译,脱机(二)
In the digital era, how can enterprises manage data security and ensure the security of data assets
数据处理时代,数据分析成为基础建设
位运算题目
The value of Bi in the enterprise: business analysis and development decision
Uniapp native JS to convert the Gregorian calendar to the lunar calendar
Adobe Premiere foundation - tool use (selection tool, razor tool, and other common tools) (III)
“数字化转型,数据先行”,谈谈数据治理对企业来说到底有多重要
企业管理者的质疑,这么多年的信息化,我们的钱花哪去了?
实时商业智能BI(二):合理的ETL架构设计实现准实时商业智能BI
第三章 数据类型(二)
Adobe Premiere foundation - opacity (mixed mode) (XII)
[QNX hypervisor 2.2 user manual] 3.2.2 VM configuration example
Custom types: structural bodies
第一章 SQL操作符
Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
Ruijie x32pro brush openwrt enable wireless 160MHz
Stream生成的3张方式-Lambda
RK1126 新添加一个模块