版主: wanchong , wangyu , eepwwp , firedom

分享到:
共3条 1/1 1   

【转】Intel Galileo 之 OpenCV 人脸区域识别

    [您是本帖的第2459位阅读者]
wanchong
我是GG
版主

最后登陆时间:2014-06-17 08:56:07

直达楼层
1# 发表于 2014-07-09 16:01:59

既然官方镜像包含了OpenCV、Python、nodejs 等诸lib库,怎能不用一下爽爽,先试试OpenCV, 做人脸识别需要一个训练好的识别库,OpenCV库当中已经包含该文件,懒得找所以用了之前的文件,这东西网上到处是,名曰 :  haarcascade_frontalface_alt.xml

之后便可以开始了,准备一张有若干人脸的照片,别太大的,我用的jpg格式,放到与代码同目录下,准备开工上代码

 

#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;   //必须包含该命名空间

string face_cascade_name = "haarcascade_frontalface_alt.xml";  //同目录下的 文件
CascadeClassifier face_cascade;   //模式识别类

void detectAndDisplay( Mat frame );  //人脸检测函数声明

int main(){                    //主函数
    Mat image;                //图象矩阵
    image = imread("test.jpg");  //读入图象

    if(image.empty()){
        printf("[error] No Picture has been read...n");
        return -1;
    }

    if( !face_cascade.load( face_cascade_name ) ){  //读入训练好的识别库
        printf("[error] Can't load Data File...n");
        return -1; 
    }

    detectAndDisplay(image);           //检测并输出

    waitKey(0);           //等待按键退出
}

void detectAndDisplay( Mat frame ){
    std::vector<Rect> faces;     //人脸数组
    Mat frame_gray;                  //图象数组
    bool value;                         
    cvtColor( frame, frame_gray, CV_BGR2GRAY );  //转换为灰度图
    equalizeHist( frame_gray, frame_gray );  //归一化图像亮度和增强对比度

    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );  //检测并存储脸的数据

    for( int i = 0; i < faces.size(); i++ ){   //给每个脸上画一个椭圆
        Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
        ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
    }
    value = imwrite("out.jpg",frame);  //保存 输出图象
        if(value)
   printf("Write OK.....n");    //显示成功
}

这样便完成了

开始编译 $ g++ `pkg-config opencv --libs --cflags opencv` facedetect.cpp -o facedetect

Intel Galileo 之 OpenCV 人脸区域识别

运行成功,耗时5秒左右,看图对比

Intel Galileo 之 OpenCV 人脸区域识别

Intel Galileo 之 OpenCV 人脸区域识别

OpenCV.zip




关键词:Intel    伽利略    Galileo    OpenCV        

RE: 【转】Intel Galileo 之 OpenCV 人脸区域识别

forele
我是MM
高级会员

最后登陆时间:2015-01-13 18:18:53

2# 发表于 2014-07-09 16:15:10
帅锅图

RE: 【转】Intel Galileo 之 OpenCV 人脸区域识别

啸风
我是GG
高级会员

最后登陆时间:2014-04-17 19:19:45

3# 发表于 2014-07-09 20:08:59
看到“财路”了~~!
共3条 1/1 1   
快速回复主题
  • 匿名不能发帖!请先 [ 登陆 注册 ]