资源简介
基于haar特征adaboost训练的xml 文件
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< }//对已检测出的手掌进行下一步处理
/** 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 < palmAll.size(); j++)
{
//提取图像手的区域
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); //显示手掌方框
//设置矩形掩模
mask(rect).setTo(255);
result = frame(rect);
i = j + 1;
}
//cv::Canny(resultresult80150);
//cv::imshow(“result“ result);
std::cout << “Palm Number :“ << i << endl;
vector channels;
imshow(“result“ result);
//取出手掌区域,下面写手掌分割的代码
//输入数据 Mat result/Y
Mat contours;
blur(result result Size(3 3));
Canny(result contours 60 120); //边缘检测
vector lines;
imshow(“Canny“ contours);
HoughLines
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 284238 2017-03-25 09:40 myhaar.xm
文件 4094 2017-05-19 16:56 Palm.cpp
----------- --------- ---------- ----- ----
288332 2
评论
共有 条评论