资源简介
包含手势识别(拳头)的python代码和cpp代码以及最重要的训练好的xml文件
代码片段和文件信息
//
// main.cpp
// handDetection
//
// Created by 刘鹏 on 2016/11/27.
// Copyright © 2016年 刘鹏. All rights reserved.
//
#include
#include
#include
#include
using namespace std;
using namespace cv;
// Global variables
// Copy this file from opencv/data/haarscascades to target folder
string face_cascade_name = “/Users/liupeng/Desktop/my/handDetection/handDetection/hand.xml“;
CascadeClassifier *face_cascade;
string window_name = “Capture - Face detection“;
int filenumber; // Number of file to be saved
string filename;
// Function Headers
class faceDetection
{
private:
std::vector faces;
public:
faceDetection();
~faceDetection();
void detectAndDisplay(Mat frame);
};
faceDetection::faceDetection()
{
}
faceDetection::~faceDetection()
{
}
// Function detectAndDisplay
void faceDetection::detectAndDisplay(Mat frame)
{
// 报错问题所在,。
// std::vector faces;
Mat frame_gray;
Mat crop;
Mat res;
Mat gray;
string text;
stringstream sstm;
cvtColor(frame frame_gray COLOR_BGR2GRAY);
equalizeHist(frame_gray frame_gray);
// Detect faces
face_cascade->detectMultiScale(frame_gray faces 1.1 2 0 | CASCADE_SCALE_IMAGE Size(30 30));
// Set Region of Interest
cv::Rect roi_b;
cv::Rect roi_c;
size_t ic = 0; // ic is index of current element
int ac = 0; // ac is area of current element
size_t ib = 0; // ib is index of biggest element
int ab = 0; // ab is area of biggest element
for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces)
{
roi_c.x = faces[ic].x;
roi_c.y = faces[ic].y;
roi_c.width = (faces[ic].width);
roi_c.height = (faces[ic].height);
ac = roi_c.width * roi_c.height; // Get the area of current element (detected face)
roi_b.x = faces[ib].x;
roi_b.y = faces[ib].y;
roi_b.width = (faces[ib].width);
roi_b.height = (faces[ib].height);
ab = roi_b.width * roi_b.height; // Get the area of biggest element at beginning it is same as “current“ element
if (ac > ab)
{
ib = ic;
roi_b.x = faces[ib].x;
roi_b.y = faces[ib].y;
roi_b.width = (faces[ib].width);
roi_b.height = (faces[ib].height);
}
crop = frame(roi_b);
resize(crop res Size(128 128) 0 0 INTER_LINEAR); // This will be needed later while saving images
cvtColor(crop gray CV_BGR2GRAY); // Convert cropped image to Grayscale
// Form a filename
filename = ““;
stringstream ssfn;
ssfn << filenumber << “.png“;
filename = ssfn.str();
filenumber++;
// imwrite(filename gray);
Point pt1(faces[ic].x faces[ic].y); // Disp
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-07-17 22:31 手势识别(拳头)\
目录 0 2017-07-17 22:22 手势识别(拳头)\__MACOSX\
文件 263 2016-11-27 14:53 手势识别(拳头)\__MACOSX\._hand.mp4
文件 175 2011-11-29 14:19 手势识别(拳头)\__MACOSX\._hand.xm
文件 504 2016-11-27 14:55 手势识别(拳头)\__MACOSX\._main.cpp
文件 10261034 2016-11-27 14:53 手势识别(拳头)\hand.mp4
文件 72462 2011-11-29 14:19 手势识别(拳头)\hand.xm
文件 4643 2016-11-27 14:55 手势识别(拳头)\main.cpp
文件 825 2017-07-17 22:31 手势识别(拳头)\video_demo.py
文件 824 2017-07-17 22:29 手势识别(拳头)\video_demo.py~
评论
共有 条评论