文章标题基于opencv 实现人脸定位

这里写代码


#include <opencv2\opencv.hpp>
#include<time.h>
#include<string>
#include<vector>
#include<iostream>
#include<cv.h>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;  
using namespace std;
ostream os;
istream is;
int main( )  
{
    String cascadename = "haarcascade_frontalface_alt2.xml";
    CascadeClassifier cascade;
    cascade.load(cascadename);
    VideoCapture capture(0);
    cout << "测试点2" << endl;
    const static Scalar colors[] = { CV_RGB(0,0,255),
        CV_RGB(0,128,255),
        CV_RGB(0,255,255),
        CV_RGB(0,255,0),
        CV_RGB(255,128,0),
        CV_RGB(255,255,0),
        CV_RGB(255,0,0),
        CV_RGB(255,0,255) };
        vector<Rect>faces;
        vector<Rect>eye;
    while(1)  
    {  Mat edges; 
    clock_t start, finish;
    double totaltime;
    start = clock();
        //cout << "测试点3" << endl;
        Mat frame;  //定义一个Mat变量,用于存储每一帧的图像

        capture>>frame; 
        //cout << "测试点3.1" << endl;
        Mat gray;
        //cout << "测试点3.2" << endl;
        boxFilter(frame, gray, -1, Size(7, 7));
        //threshold(frame, gray, 170, 255, CV_THRESH_BINARY);
        cvtColor(gray,edges,CV_BGR2GRAY);
        Mat temp;
        cout << "neicun" << sizeof(edges) << endl;
        //cout << "测试点3.3" << endl;
        equalizeHist(edges,edges);
        start = clock();
        cascade.detectMultiScale(edges,faces,1.1,3,0|CV_HAAR_DO_CANNY_PRUNING);
        finish = clock();
        totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
        cout << "\n此程序的运行时间为" << totaltime << "秒!" << endl;
        if(faces.size()==0)
        {
            cout << "跳过" << endl;
            //continue;
        }
        else
        {

            int i = 0;
            for (vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++, i++)
            {
                Point center;
                Point center2;
                Scalar color = colors[i % 8];
                center.x = cvRound(r->x);
                center.y = cvRound(r->y);
                center2.x = cvRound(r->x + r->width);
                center2.y = cvRound(r->y + r->height);
                rectangle(frame, center, center2, color);
            }
        }


        //cout << "断点7" << endl;
        cout << "测试点5" << endl;
        imshow("result", frame);
        waitKey(1);
    }  
    return 0;     
}  

“`大概思路 先对图像进行 高斯滤波 降噪 灰度处理 均衡化处理 用Haar 方法 侦测 人脸 并画出 在画人脸是需要注意 如果detectMultiScale()函数没有检测到 定位点 就需要跳过 标记圈脸函数 detectMultiScale()的参数也需要注意 不详解。。。。。。。本人新手 能力有限 欢迎大家来 提出问题以及 我的不足。。。。再次谢谢。!结果(https://img-blog.csdn.net/20161023000427171)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值