以下程式來自opencv自帶例程:
#include "stdafx.h"
#include "opencv/highgui.h"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include #include using namespace std;
using namespace cv;
void help()
void detectanddraw(mat& img, cascadeclassifier& cascade);
//string cascadename = "h:/opencv2.4/opencv/data/haarcascades/haarcascade_frontalface_alt.xml";
string cascadename = "h:/opencv2.4/opencv/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml";//nestedcascadename
int main( int argc, const char** argv )
const string cascadeopt = "--cascade1=";
size_t cascadeoptlen = cascadeopt.length();
string inputname;
for( int i = 1; i < argc; i++ )
else if( argv[i][0] == '-' )
else
inputname.assign( argv[i] );
} cascadeclassifier cascade;
if( !cascade.load( cascadename ) )
if( inputname.size() ) }
else
cvnamedwindow( "result", 1 );
if( capture )
waitkey(0);
_cleanup_:
cvreleasecapture( &capture );
} else if( !image.empty() )
else
cvdestroywindow("result");
return 0;
}void detectanddraw( mat& img, cascadeclassifier& cascade)
; mat gray;
mat frame( cvround(img.rows), cvround(img.cols), cv_8uc1 );
cvtcolor( img, gray, cv_bgr2gray );
resize( gray, frame, frame.size(), 0, 0, inter_linear );
equalizehist( frame, frame );
t = (double)cvgettickcount();
cascade.detectmultiscale( frame, faces,
1.1, 2, 0
//|cv_haar_find_biggest_object
//|cv_haar_do_rough_search
|cv_haar_scale_image
, size(30, 30) );
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++ )
cv::imshow( "result", img );
}
效果還行,就是效率還達不到實時,只能是準實時的水平吧。效果圖:
OpenCV2 4 例程四 形態學操作
以下程式來自opencv例程 define cv no backward compatibility include stdafx.h include opencv2 imgproc imgproc.hpp include opencv2 highgui highgui.hpp include in...
Opencv2 4學習 HOG特徵
一 什麼是hog特徵 二 如何提取hog特徵 三 視窗 win 塊 block 細胞 cell 與畫素的關係 四 特徵向量維度數目的計算 五 關於梯度直方圖的計算 重點 1 影象卷積 影象梯度一般利用影象與梯度運算元卷積實現,關於這部分內容,可以參考opencv2.4學習 影象卷積 2 梯度運算元 ...
Opencv2 4學習 Mat矩陣的建立
類詳細解釋參見 1 mat mat 無引數構造方法 2 mat mat int rows,int cols,int type 建立行數為 rows,列數為 col,型別為 type 的影象 3 mat mat size size,int type 建立大小為 size,型別為 type 的影象 4 ...