基於Hog特徵的行人檢測

2021-07-31 20:17:22 字數 2885 閱讀 7356

1、先建立相應的txt檔案

f:\pedestrian\image_00000101_0.png

f:\pedestrian\image_00000105_0.png

f:\pedestrian\image_00000108_0.png

f:\pedestrian\image_00000110_0.png

f:\pedestrian\image_00000115_0.png

f:\pedestrian\image_00000118_0.png

f:\pedestrian\image_00000120_0.png

f:\pedestrian\image_00000124_0.png

f:\pedestrian\image_00000130_0.png

f:\pedestrian\image_00000135_0.png

f:\pedestrian\image_00000137_0.png

f:\pedestrian\image_00000139_0.png

f:\pedestrian\image_00000140_0.png

2、main函式

#include "opencv2/imgproc/imgproc.hpp"  

#include "opencv2/objdetect/objdetect.hpp"

#include "opencv2/highgui/highgui.hpp"

#include #include #include using namespace cv;

using namespace std;

int main(int argc, char** argv)

//img = imread(argv[1]);

//img = imread("neglistinria.txt");

//if( img.data )

//

//else

//

//}

hogdescriptor hog;

hog.setsvmdetector(hogdescriptor::getdefaultpeopledetector());

namedwindow("people detector", 1);

for(;;)

printf("%s:\n", filename);

if(!img.data)

continue;

fflush(stdout);//清除檔案緩衝區。以寫方式開啟檔案時,將緩衝區內容寫入檔案

vectorfound, found_filtered;

double t = (double)gettickcount();

// run the detector with default parameters. to get a higher hit-rate

// (and more false alarms, respectively), decrease the hitthreshold and

// groupthreshold (set groupthreshold to 0 to turn off the grouping completely).

hog.detectmultiscale(img, found, 0, size(8,8), size(32,32), 1.05, 2);

/* img – source image.

found_locations – objects boundaries(x,y,width,height).

hit_threshold – threshold for the distance between features and svm classifying plane.

win_stride – window stride. it must be a multiple of block stride.

padding – mock parameter to keep the cpu inte***ce compatibility. it must be (0,0). ????

scale0 – coefficient of the detection window increase.

group_threshold – coefficient to regulate the similarity threshold. when detected, some

objects can be covered by many rectangles. 0 means not to perform grouping. 原本能檢測乙個人,當設為4的時候居然沒了

*/

t = (double)gettickcount() - t;

printf("tdetection time = %gms\n", t*1000./cv::gettickfrequency());

size_t i, j;

for( i = 0; i < found.size(); i++ )//去掉空間中具有內外包含關係的區域,保留大的

for( i = 0; i < found_filtered.size(); i++ )

imshow("people detector", img);

int c = waitkey(5000) & 255;

if( c == 'q' || c == 'q' || !f)

break;

} if(f)

fclose(f);

return 0;

}

OpenCV 基於HOG特徵的行人檢測

opencv中提供了hog的行人檢測 pedestrain detection 類。cv hogdescriptor類的建構函式的各引數的定義 cpp view plain copy cv wrap hogdescriptor winsize 64,128 detect window blocksi...

行人檢測 HOG運算元

梯度直方圖特徵 hog 是一種對影象區域性重疊區域的密集型描述符 它通過計算區域性區域的梯度方向直方圖來構成特徵。hog特徵結合 svm分類器已經被廣泛應用於影象識別中,尤其在行人檢測中獲得了極大的成功。需要提醒的是,hog svm 進行行人檢測的方法是法國研究人員 dalal 在2005 的cvp...

HOG演算法 行人檢測

hog histogram of oriented gridients 是2005年提出描述行人特徵的演算法,在當年取得了突破性的進展,處理在行人檢測領域,在其他識別方面hog也取得了不錯的效果。hog通過計算和統計影象區域性區域的梯度方向直方圖來形成描述特徵 在一張影象中,人與外界存在乙個邊緣,通...