ASM模型对人脸特征点的检测
生活随笔
收集整理的這篇文章主要介紹了
ASM模型对人脸特征点的检测
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<span style="font-size:18px;">// Face_ASM.cpp : 定義控制臺應用程序的入口點。
////#include "stdafx.h"
#include <iostream>
#include <vector>
//#include "stdafx.h"#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#pragma comment(lib,"asmlibraryD.lib")#include "asmfitting.h"using namespace std;
using namespace cv;int main()
{Point2D32f pt;int circle_x, circle_y, i, j;//IplImage* img = cvLoadImage("D:6.jpg");Mat img = imread("D:6.jpg");IplImage* img1;img1 = &IplImage(img);//*****************人臉檢測****************************************************************************CascadeClassifier face_cascade; //識別人臉的功能if (!face_cascade.load("haarcascade_frontalface_alt.xml")){cout << "Cascadeclassifier load false!" << endl;return -1;}vector<Rect> face_vec; //保存人臉的個數,vector保存到容器中Mat pic_RGB, pic_GRAY;pic_RGB = img;cvtColor(pic_RGB, pic_GRAY, CV_RGB2GRAY);//進行灰度變換equalizeHist(pic_GRAY, pic_GRAY);//進行直方圖均衡化face_cascade.detectMultiScale(pic_GRAY, face_vec, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(10, 10)); //檢測數人臉if (!face_vec.size())cout << "檢測不到人臉!" << endl;elsecout << "檢測到 " << face_vec.size() << "張人臉!" << endl;for (i = 0; i<(int)face_vec.size(); i++){Point p1((int)face_vec[i].x, (int)face_vec[i].y);Point p2((int)(face_vec[i].x + face_vec[i].width), (int)(face_vec[i].y + face_vec[i].height*1.1));rectangle(img, p1, p2, Scalar(255, 0, 0), 1, 8, 0); } //矩形框顯示出人臉//imshow("facedetect_test",pic_RGB);//***************ASM特征點匹配*************************************************************************if (!face_vec.size()){cout << "沒有檢測到人臉,無法ASM特征點匹配" << endl;return -1;}//下面上是ASM模型對人臉中特征點的檢測asm_shape shape, detshape;asmfitting fit_asm;if (fit_asm.Read("my68-1d.amf") == false){cout << "ASM特征點模版載入失敗,退出!" << endl;return -1;}//模版位置初始化detshape.Resize(2);for (i = 0; i<(int)face_vec.size(); i++){detshape[0].x = (float)face_vec[i].x;//face_rect是cvRect型結構體的實體,cvRect結構體的成員為x,y,width,heightdetshape[0].y = (float)face_vec[i].y;detshape[1].x = (float)(face_vec[i].x + face_vec[i].width);detshape[1].y = (float)(face_vec[i].y + face_vec[i].height);InitShapeFromDetBox(shape, detshape, fit_asm.GetMappingDetShape(), fit_asm.GetMeanFaceWidth());//給人臉圖像貼上ASM模版bool b = fit_asm.ASMSeqSearch(shape, img1, 0, true, 30);//對準人臉特征點//提取特征點坐標位置// for(j=0;j<68;j++)// {//pt = shape[j];// circle_x=cvRound(pt.x);// circle_y=cvRound(pt.y);// cvCircle( img,cvPoint(circle_x,circle_y), 2, cvScalar(255,0,0),1, 8, 0 );// }pt = shape[27];circle_x = cvRound(pt.x);circle_y = cvRound(pt.y);circle(img, cvPoint(circle_x, circle_y), 2, cvScalar(0, 255, 0), 1, 8, 0);pt = shape[29];circle_x = cvRound(pt.x);circle_y = cvRound(pt.y);circle(img, cvPoint(circle_x, circle_y), 2, cvScalar(0, 255, 0), 1, 8, 0);pt = shape[34];circle_x = cvRound(pt.x);circle_y = cvRound(pt.y);circle(img, cvPoint(circle_x, circle_y), 2, cvScalar(0, 255, 0), 1, 8, 0);pt = shape[32];circle_x = cvRound(pt.x);circle_y = cvRound(pt.y);circle(img, cvPoint(circle_x, circle_y), 2, cvScalar(0, 255, 0), 1, 8, 0);}imshow("facedetect_test", img);if (cvWaitKey(0) >= 0)return 0;return 0;
}
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>
代碼下載地址:
http://download.csdn.net/detail/qq_18343569/9085929
點擊打開鏈接
總結
以上是生活随笔為你收集整理的ASM模型对人脸特征点的检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: opencv中 当你直接把别人的程序拖
- 下一篇: squeeze函数