当前位置:网站首页>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;
}边栏推荐
- uniapp 原生js实现公历转农历
- Vcsa7u3c installation tutorial
- 连续六年稳居中国SDN(软件)市场份额第一
- 第三章 数据类型(二)
- 什么是商业智能BI,谈谈商业智能BI的定义与作用
- 【接口教程】EasyCVR如何通过接口设置平台级联?
- 如何设置 SaleSmartly 以进行 Google Analytics(分析)跟踪
- Adobe Premiere基础(轨道相关)(五)
- The question of enterprise managers, where have we spent our money after so many years of informatization?
- In 2021, the world's top ten analog IC suppliers: Ti ranked first, and skyworks' revenue growth was the highest
猜你喜欢

The value of Business Intelligence BI. Is visual report equal to Business Intelligence BI?

RK1126 新添加一个模块

Huawei cloud Kunpeng devkit code migration practice

Seata installing the window environment

Adobe Premiere基础(视频的最后一步字幕添加)(六)

How to realize the management "desire" of Business Intelligence BI service objects and enterprise managers?

uniapp uview 框架的form表单,输入校验手机号、校验微信号

HelloWorld example of TestNG and how to run it from the command line

Salesmartly | add a new channel slack to help you close the customer relationship

In the introductory study of data visualization, we should be alert to pitfalls and misunderstandings and grasp key nodes
随机推荐
第三章 数据类型(二)
微信小程序,获取当前页面,判断当前页面是不是tabbar页面
[QNX hypervisor 2.2 user manual] 3.3 configure guest
商业智能BI在企业的价值之:业务分析发展决策
MySQL索引失效场景
Custom types: structural bodies
Db2 SQL PL中的控制语句
How to set up salesmartly for Google Analytics tracking
uniapp uview 框架的form表单,输入校验手机号、校验微信号
Stream生成的3张方式-Lambda
Semiconductor silicon continued to fall short of demand, and Shenggao's long-term contract price rose by 30%!
【QNX Hypervisor 2.2 用户手册】3.2.1 VM配置语法
[kuangbin]专题十二 基础DP1
Screen output of DB2 stored procedure, output parameters, and return result set
台积电刘德音:不担心半导体库存修正及美日韩合作,今年业绩将增长30%!
Wireshark学习笔记(一)常用功能案例和技巧
In the digital age, why should enterprises make digital transformation?
How can bi help enterprises reduce labor, time and management costs?
Uniapp native JS to convert the Gregorian calendar to the lunar calendar
【接口教程】EasyCVR如何通过接口设置平台级联?