資源簡介
深圳大學計算機副教授于仕琪及其團隊編寫的人臉檢測函數,包含動態鏈接庫,函數的使用說明,以及函數的調用示例。可下載學習,并與opencv提供的函數進行對比
代碼片段和文件信息
#include?
#include?“facedetect-dll.h“
#pragma?comment(lib“libfacedetect.lib“)
using?namespace?cv;
void?find_face1(Mat?gray);
void?find_face2(Mat?gray);
void?find_face3(Mat?gray);
int?main(int?argc?char*?argv[])
{
//load?an?image?and?convert?it?to?gray?(single-channel)
Mat?gray?=?imread(“4.jpg“?CV_LOAD_IMAGE_GRAYSCALE);
Mat?show;
cvtColor(grayshow8);
if?(gray.empty())
{
fprintf(stderr?“Can?not?load?the?image?file.\n“);
return?-1;
}
find_face1(gray);
find_face2(gray);
find_face3(gray);
waitKey(0);
return?0;
}
void?find_face1(Mat?gray)
{
Mat?show;
cvtColor(gray?show?8);
int?*?pResults?=?NULL;
pResults?=?facedetect_frontal((unsigned?char*)(gray.ptr(0))?gray.cols?gray.rows?gray.step
1.2f?3?24);
printf(“%d?frontal?faces?detected.\n“?(pResults???*pResults?:?0));
//print?the?detection?results
for?(int?i?=?0;?i?(pResults???*pResults?:?0);?i++)
{
short?*?p?=?((short*)(pResults?+?1))?+?6?*?i;
int?x?=?p[0];
int?y?=?p[1];
int?w?=?p[2];
int?h?=?p[3];
int?neighbors?=?p[4];
printf(“face_rect=[%d?%d?%d?%d]?neighbors=%d\n“?x?y?w?h?neighbors);
rectangle(show?Point(x?y)?Point(x?+?w?y?+?h)?Scalar(0?0?255)?2?8);
}
imshow(“facedetect_frontal“?show);
}
void?find_face2(Mat?gray)
{
Mat?show;
cvtColor(gray?show?8);
int?*?pResults?=?NULL;
pResults?=?facedetect_multiview_reinforce((unsigned?char*)(gray.ptr(0))?gray.cols?gray.rows?gray.step
1.2f?5?24);
printf(“%d?faces?detected.\n“?(pResults???*pResults?:?0));
//print?the?detection?results
for?(int?i?=?0;?i?(pResults???*pResults?:?0);?i++)
{
short?*?p?=?((short*)(pResults?+?1))?+?6?*?i;
int?x?=?p[0];
int?y?=?p[1];
int?w?=?p[2];
int?h?=?p[3];
int?neighbors?=?p[4];
printf(“face_rect=[%d?%d?%d?%d]?neighbors=%d\n“?x?y?w?h?neighbors);
rectangle(show?Point(x?y)?Point(x?+?w?y?+?h)?Scalar(0?0?255)?2?8);
}
imshow(“facedetect_multiview_reinforce“?show);
}
void?find_face3(Mat?gray)
{
Mat?show;
????cvtColor(gray?show?8);
????int?*?pResults?=?NULL;
pResults?=?facedetect_frontal_tmp((unsigned?char*)(gray.ptr(0))?gray.cols?gray.rows?gray.step
1.2f?5?24);
printf(“%d?faces?detected.\n“?(pResults???*pResults?:?0));
//print?the?detection?results
for?(int?i?=?0;?i?(pResults???*pResults?:?0);?i++)
{
short?*?p?=?((short*)(pResults?+?1))?+?6?*?i;
int?x?=?p[0];
int?y?=?p[1];
int?w?=?p[2];
int?h?=?p[3];
int?neighbors?=?p[4];
printf(“face_rect=[%d?%d?%d?%d]?neighbors=%d\n“?x?y?w?h?neighbors);
rectangle(show?Point(x?y)?Point(x?+?w?y?+?h)?Scalar(0?0?255)?2?8);
}
imshow(“facedetect_frontal_tmp“?show);
}
評論
共有 條評論