基於OpenCV的簡單的人臉檢測

2021-07-05 01:25:34 字數 2094 閱讀 7742

這個是在數字影象處理課程裡面的乙個小實踐內容。參考網上已有**重新配置編譯,效果不錯。

人臉識別的庫使用的是haarcascade_frontalface檔案,包含在opencv當中的。

關鍵部分**如下:

//本原始碼只為學習交流之用 

//typersever from gzhu

static cvmemstorage* storage = 0;

static cvhaarclassifiercascade* cascade = 0;

void detect_and_draw( iplimage* image );

const char* cascade_name =

"haarcascade_frontalface_alt.xml";

/* "haarcascade_profileface.xml";*/

int main( int argc, char** argv )

cvnamedwindow( "result", 1 );

//const char* filename = "d:/程式/opencv/mytest/mytestfacedetection/lena.jpg";

//iplimage* image = cvloadimage( filename, 1 );

//cvshowimage( "first", image );

storage = cvcreatememstorage(0);

while(1)

cvreleaseimage( &pframe );

cvdestroywindow("result");

return 0;

}void detect_and_draw(iplimage* img )

},},},},

},},},}

};//just some pretty colors to draw with

//image preparation

// iplimage* gray = cvcreateimage(cvsize(img->width,img->height),8,1);

iplimage* small_img=cvcreateimage(cvsize(cvround(img->width/scale),cvround(img->height/scale)),8,1);

cvcvtcolor(img,gray, cv_bgr2gray);

cvresize(gray, small_img, cv_inter_linear);

cvequalizehist(small_img,small_img); //直方圖均衡

//detect objects if any

// cvclearmemstorage(storage);

double t = (double)cvgettickcount();

cvseq* objects = cvhaardetectobjects(small_img,

cascade,

storage,

1.1,

2, 0/*cv_haar_do_canny_pruning*/,

cvsize(30,30));

t = (double)cvgettickcount() - t;

printf( "detection time = %gms\n", t/((double)cvgettickfrequency()*1000.) );

//loop through found objects and draw boxes around them

for(int i=0;i<(objects? objects->total:0);++i)

for( int i = 0; i < (objects? objects->total : 0); i++ )

cvshowimage( "result", img );

cvreleaseimage(&gray);

cvreleaseimage(&small_img);

}

工程檔案見本人資源。歡迎學習交流。

python基於opencv最簡單的人臉檢測01

準備開始學習opencv4 opencv 的意思就是開放的計算機視覺,是乙個基於c 的超實用庫 執行此 需要安裝opencv庫 可以通過pip安裝 以下是基於opencv自帶的人臉檢測模型的人臉檢測 import cv2 as cv defplot rectangle image,faces for...

Python OpenCV實現簡單的人臉檢測

匯入opencv庫 import cv2 載入特徵分類器 opencv自帶 face cascade cv2.cascadeclassifier haarcascade frontalface default.xml 開啟電腦攝像頭 capture cv2.videocapture 0 獲得攝像頭捕...

基於opencv的人臉識別

1前言參考的是 這篇用的是dlib的對齊還加了mask。本文方法 人臉檢測 shiqiyu libfacedetection opencv提取ptr類 2 facedetect.h include include include include include facedetect dll.h us...