資源簡(jiǎn)介
基于haar特征adaboost訓(xùn)練的xml 文件
C++ 區(qū)域生長(zhǎng)+邊緣檢測(cè)手掌分割

代碼片段和文件信息
#include?“opencv2/objdetect/objdetect.hpp“
#include?“opencv2/highgui/highgui.hpp“
#include?“opencv2/imgproc/imgproc.hpp“
#include?
#include?
#define?PI?3.1415926?
using?namespace?std;
using?namespace?cv;
void?Palm_Carve(cv::Mat?palm)
{
//cout<<1< }//對(duì)已檢測(cè)出的手掌進(jìn)行下一步處理
/**?Function?Headers?*/
void?Palm_Detect(Mat?frame);
void?RestoreVectors(vector>&?vecs_bank?vector&?vecAll);
/**?Global?variables?*/
String?palm_cascade_name?=?“myhaar.xml“;
//String?fist_cascade_name?=?“haarcascade_frontalface_alt.xml“;
CascadeClassifier?palm_cascade;
string?window_name?=?“Face?detection“;
/**?@function?main?*/
int?main(int?argc?const?char**?argv)
{
CvCapture*?capture;
Mat?frame;
//--?1.?Load?the?cascades
if?(!palm_cascade.load(palm_cascade_name)){?printf(“--(!)Error?loading\n“);?return?-1;?};
//--?2.?Read?the?video?stream
capture?=?cvCaptureFromCAM(0);
if?(capture)
{
while?(true)
{
frame?=?cvQueryframe(capture);
//--?3.?Apply?the?classifier?to?the?frame
if?(!frame.empty())
{
Palm_Detect(frame);
}
else
{
printf(“?--(!)?No?captured?frame?--?Break!“);?break;
}
int?c?=?waitKey(1);
if?((char)c?==?‘q‘?||?(char)c?==?‘Q‘?||?27?==?c)?{?break;?}
}
}
cvReleaseCapture(&capture);
return?0;
}
/**?@function?Palm_Detect?*/
void?Palm_Detect(Mat?frame)
{
std::vector?face;
static?vector>?Palm_stack;
const?int?MAX_NUM?=?3;
Mat?frame_gray;
cvtColor(frame?frame_gray?CV_BGR2GRAY);
//equalizeHist(?frame_gray?frame_gray?);
Size?min?max;
min.width?=?100;
min.height?=?100;
max.width?=?450;
max.width?=?450;
//--?Palm?detection
palm_cascade.detectMultiScale(frame_gray?face?1.1?3?0?min?max);
Palm_stack.push_back(face);
if?(Palm_stack.size()?>?MAX_NUM)
Palm_stack.erase(Palm_stack.begin());
vector?palmAll;
RestoreVectors(Palm_stack?palmAll);
groupRectangles(palmAll?2);
Mat?result(10?10?CV_8UC3?cv::Scalar::all(1));
int?i?=?0;
for?(size_t?j?=?0;?j? {
//提取圖像手的區(qū)域
Mat?mask?=?Mat::zeros(frame.size()?CV_8UC1);
Rect?rect;
rect.x?=?palmAll[j].x;
rect.width?=?palmAll[j].width;
if?(palmAll[j].y?<=?50)
{
rect.y?=?palmAll[j].y;
rect.height?=?palmAll[j].height;
}
else
{
rect.y?=?palmAll[j].y?-?50;
rect.height?=?palmAll[j].height?+?50;
}
//rectangle(frame?rect?Scalar(25500)?1);?//顯示手掌方框
//設(shè)置矩形掩模
mask(rect).setTo(255);
result?=?frame(rect);
i?=?j?+?1;
}
//cv::Canny(resultresult80150);
//cv::imshow(“result“?result);
std::cout?<“Palm?Number?:“?<
vector?channels;
imshow(“result“?result);
//取出手掌區(qū)域,下面寫手掌分割的代碼
//輸入數(shù)據(jù)?Mat?result/Y
Mat?contours;
blur(result?result?Size(3?3));
Canny(result?contours?60?120);??//邊緣檢測(cè)??
vector?lines;
imshow(“Canny“?contours);
HoughLines
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????284238??2017-03-25?09:40??myhaar.xm
?????文件???????4094??2017-05-19?16:56??Palm.cpp
-----------?---------??----------?-----??----
???????????????288332????????????????????2
評(píng)論
共有 條評(píng)論