vs13 opencv3 0 人臉檢測

2021-07-11 16:06:06 字數 2880 閱讀 6699

背景:使用opencv3.0進行人臉識別的第一步:完**臉的檢測

環境:vs2013,opencv3.0 alpha版

**:由/source/samples/cpp/facedetect.cpp下更改而來

#include "opencv2/objdetect.hpp"

#include "opencv2/imgcodecs.hpp"

#include "opencv2/videoio.hpp"

#include "opencv2/highgui.hpp"

#include "opencv2/imgproc.hpp"

#include "opencv2/core/utility.hpp"

#include "opencv2/videoio/videoio_c.h"

#include "opencv2/highgui/highgui_c.h"

#include

#include

#include

#include

using

namespace

std;

using

namespace cv;

static

void help()

void detectanddraw(mat& img, cascadeclassifier& cascade,

cascadeclassifier& nestedcascade,

double scale, bool tryflip);

//要使用到的兩個cascade檔案,用於聯合檢測人臉,opencv自帶了多個xml檔案,在opencv安裝目錄下的/source/data/haarcascades/ 資料夾內

string cascadename = "c:\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml";

string nestedcascadename = "c:\\opencv\\sources\\data\\haarcascades\\haarcascade_eye_tree_eyeglasses.xml";//檢測眼睛

int main()

image = imread(srcimagefile);

cvnamedwindow("result", 1);

cout

<< "in image read"

<< endl;

if (!image.empty())

cvdestroywindow("result");

return0;}

void detectanddraw(mat& img, cascadeclassifier& cascade,

cascadeclassifier& nestedcascade,

double scale, bool tryflip)

;//用於畫線

mat gray, smallimg(cvround(img.rows / scale), cvround(img.cols / scale), cv_8uc1);

cvtcolor(img, gray, color_bgr2gray);

resize(gray, smallimg, smallimg.size(), 0, 0, inter_linear);

equalizehist(smallimg, smallimg);

t = (double)cvgettickcount();

cascade.detectmultiscale(smallimg, faces,

1.1, 2, 0

//|cascade_find_biggest_object

//|cascade_do_rough_search

| cascade_scale_image

,size(30, 30));

if (tryflip)

}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++)

else

rectangle(img, cvpoint(cvround(r->x*scale), cvround(r->y*scale)),

cvpoint(cvround((r->x + r->width - 1)*scale), cvround((r->y + r->height - 1)*scale)),

color, 3, 8, 0);

if (nestedcascade.empty())

continue;

smallimgroi = smallimg(*r);

nestedcascade.detectmultiscale(smallimgroi, nestedobjects,

1.1, 2, 0

//|cascade_find_biggest_object

//|cascade_do_rough_search

//|cascade_do_canny_pruning

| cascade_scale_image

,size(30, 30));

for (vector

::const_iterator nr = nestedobjects.begin(); nr != nestedobjects.end(); nr++)

}cv::imshow("result", img);

}

Opencv學習二 人臉檢測程式

在上面的 中,我們人臉檢測使用的是cv2 cascadeclassifier 函式,它可以檢測中所有的人臉。在該函式中,各引數和返回值的含義為 image 待檢測影象,通常為灰度影象。scalefactor 表示前後兩次的掃瞄中,搜尋視窗的縮放比例。minneighbors 表示構成檢測目標的相鄰矩...

基於qt和opencv3人臉檢測

第一步 opencv裡面人臉檢測的方法 在opencv中,人臉檢測用的是harr或lbp特徵,分類演算法用的是adaboost演算法。這種演算法需要提前訓練大量的,非常耗時,因此opencv已經訓練好了,把訓練結果存放在一些xml檔案裡面。上圖中資料夾的名字 haarcascades hogcasc...

opencv3 人臉識別 不同顏色圓圈 圈出

原 include include include include using namespace cv using namespace std void detectanddraw mat img,cascadeclassifier cascade,cascadeclassifier nested...