资源简介
OpenCV识别出两张图片的人脸,并比较出两张人脸的相似度,并给出相似值。
包含完整的工程文件,可立即运行!!!
用facedetect功能将两张图片中的人脸检测出来
将人脸部分的图片剪切出来,存到两张只有人脸的图片里。
将这两张人脸图片转换成单通道的图像
使用直方图比较这两张单通道的人脸图像,得出相似度。

代码片段和文件信息
// opencvtest.cpp : 定義主控台應用程式的進入點。
#include “stdafx.h“
#include “opencv\cv.hpp“
#include “opencv2\objdetect\objdetect.hpp“
#include “opencv2\highgui\highgui.hpp“
#include “opencv2\imgproc\imgproc.hpp“
#include
#include
using namespace std;
using namespace cv;
String cascadeName = “D:\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml“;
IplImage* cutImage(IplImage* src CvRect rect) {
cvSetImageROI(src rect);
IplImage* dst = cvCreateImage(cvSize(rect.width rect.height)
src->depth
src->nChannels);
cvCopy(srcdst0);
cvResetImageROI(src);
return dst;
}
IplImage* detect( Mat& img CascadeClassifier& cascade double scale)
{
int i = 0;
double t = 0;
vector faces;
Mat gray smallImg( cvRound (img.rows/scale) cvRound(img.cols/scale) CV_8UC1 );
cvtColor( img gray CV_BGR2GRAY );
resize( gray smallImg smallImg.size() 0 0 INTER_LINEAR );
equalizeHist( smallImg smallImg );
t = (double)cvGetTickCount();
cascade.detectMultiScale( smallImg faces
1.3 2 CV_HAAR_SCALE_IMAGE
Size(30 30) );
t = (double)cvGetTickCount() - t;
printf( “detection time = %g ms\n“ t/((double)cvGetTickFrequency()*1000.) );
for( vector::const_iterator r = faces.begin(); r != faces.end(); r++ i++ )
{
IplImage* temp = cutImage(&(IplImage(img)) cvRect(r->x r->y r->width r->height));
return temp;
}
return NULL;
}
//画直方图用
int HistogramBins = 256;
float HistogramRange1[2]={0255};
float *HistogramRange[1]={&HistogramRange1[0]};
int CompareHist(IplImage* image1 IplImage* image2)
{
IplImage* srcImage;
IplImage* targetImage;
if (image1->nChannels != 1) {
srcImage = cvCreateImage(cvSize(image1->width image1->height) image1->depth 1);
cvCvtColor(image1 srcImage CV_BGR2GRAY);
} else {
srcImage = image1;
}
if (image2->nChannels != 1) {
targetImage = cvCreateImage(cvSize(image2->width image2->height) srcImage->depth 1);
cvCvtColor(image2 targetImage CV_BGR2GRAY);
} else {
targetImage = image2;
}
CvHistogram *Histogram1 = cvCreateHist(1 &HistogramBins CV_HIST_ARRAYHistogramRange);
CvHistogram *Histogram2 = cvCreateHist(1 &HistogramBins CV_HIST_ARRAYHistogramRange);
cvCalcHist(&srcImage Histogram1);
cvCalcHist(&targetImage Histogram2);
cvNormalizeHist(Histogram1 1);
cvNormalizeHist(Histogram2 1);
// CV_COMP_CHISQRCV_COMP_BHATTACHARYYA这两种都可以用来做直方图的比较,值越小,说明图形越相似
//printf(“CV_COMP_CHISQR : %.4f\n“ cvCompareHist(Histogram1 Histogram2 CV_COMP_CHISQR));
//printf(“CV_COMP_BHATTACHARYYA : %.4f\n“ cvCompareHist(Histogra
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 74240 2013-03-28 14:20 opencvtest\Debug\opencvtest.exe
文件 795740 2013-03-28 14:20 opencvtest\Debug\opencvtest.ilk
文件 1633280 2013-03-28 14:20 opencvtest\Debug\opencvtest.pdb
文件 2359296 2013-03-28 14:20 opencvtest\ipch\opencvtest-28dddb42\opencvtest-296a8017.ipch
文件 1578 2013-03-28 14:20 opencvtest\opencvtest\Debug\cl.command.1.tlog
文件 20286 2013-03-28 14:20 opencvtest\opencvtest\Debug\CL.read.1.tlog
文件 982 2013-03-28 14:20 opencvtest\opencvtest\Debug\CL.write.1.tlog
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 2364 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 4612 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 1044 2013-03-28 14:20 opencvtest\opencvtest\Debug\li
文件 424 2013-03-28 14:20 opencvtest\opencvtest\Debug\mt.command.1.tlog
文件 374 2013-03-28 14:20 opencvtest\opencvtest\Debug\mt.read.1.tlog
文件 374 2013-03-28 14:20 opencvtest\opencvtest\Debug\mt.write.1.tlog
文件 406 2013-03-28 09:45 opencvtest\opencvtest\Debug\opencvtest.exe.em
文件 472 2013-03-28 09:45 opencvtest\opencvtest\Debug\opencvtest.exe.em
文件 381 2013-03-28 14:20 opencvtest\opencvtest\Debug\opencvtest.exe.intermediate.manifest
文件 78 2013-03-28 14:20 opencvtest\opencvtest\Debug\opencvtest.lastbuildstate
文件 3009 2013-03-28 14:20 opencvtest\opencvtest\Debug\opencvtest.log
文件 247772 2013-03-28 14:20 opencvtest\opencvtest\Debug\opencvtest.obj
文件 1179648 2013-03-28 08:45 opencvtest\opencvtest\Debug\opencvtest.pch
文件 210 2013-03-28 09:45 opencvtest\opencvtest\Debug\opencvtest_manifest.rc
文件 602 2013-03-28 09:45 opencvtest\opencvtest\Debug\rc.command.1.tlog
文件 346 2013-03-28 09:45 opencvtest\opencvtest\Debug\rc.read.1.tlog
文件 354 2013-03-28 09:45 opencvtest\opencvtest\Debug\rc.write.1.tlog
............此处省略23个文件信息
- 上一篇:离散数学第二版课后习题答案
- 下一篇:EDAverilog课程设计报告
相关资源
- 一个人脸识别程序源码
- LDA 人脸识别
- halcon简单实现人脸识别.hdev
- 人脸识别开源SDK源码
- 百度人脸识别Demo
- delphi百度人脸识别离线SDK demo
- 讯飞人脸识别eclipse版
- Delphi7调用虹软人脸识别的测试
- [b115]FPGA上运行人脸识别源代码.zip
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- labview人脸识别283682
- 一种基于LBP和CNN的人脸识别算法
- 基于CAFFE的人脸识别系统
- LabVIEW的人脸识别代码
- 基于深度学习实现人脸识别包含模型
- 人脸识别必备的FERET人脸数据库
- 经典的人脸识别论文,包含中、英文
- H5人脸识别+活体检测眨眼摇头
- 人脸识别图像预处理技术
- iOS平台下人脸识别系统实现研究
- 人脸识别数据集说明及其
- 卷积神经网络的人脸识别样本采集+
- STM32人脸识别代码
- 科大讯飞 语音听写 人脸识别 sdk
- 基于PCA的人脸识别技术的研究
- 基于LBP算法的人脸识别研究
- 人脸识别SDK免费,可商用,有演示、
- 人脸识别三套源码含小程序源码亲测
- 基于神经网络的人脸识别(附代码)
- 基于多任务卷积网络(MTCNN)和Cente
评论
共有 条评论