opencv_traincascade训练分类器,手势识别。
来源:互联网 发布:电脑杀毒清理软件 编辑:程序博客网 时间:2024/04/29 21:11
opencv_traincascade 训练方法,参考本人的博客:Here;
xml和video下载地址:Here。
测试代码:
#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/opencv.hpp>using namespace std;using namespace cv;// Global variables// Copy this file from opencv/data/haarscascades to target folderstring 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 savedstring filename;// Function Headersclass faceDetection{private: std::vector<Rect> faces;public: faceDetection(); ~faceDetection(); void detectAndDisplay(Mat frame);};faceDetection::faceDetection(){}faceDetection::~faceDetection(){}// Function detectAndDisplayvoid faceDetection::detectAndDisplay(Mat frame){ // 报错问题所在,。 // std::vector<Rect> 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); // Display detected faces on main window - live stream from camera Point pt2((faces[ic].x + faces[ic].height), (faces[ic].y + faces[ic].width)); rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0); } // Show image sstm << "Crop area size: " << roi_b.width << "x" << roi_b.height << " Filename: " << filename; text = sstm.str(); putText(frame, text, cvPoint(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(0, 0, 255), 1, CV_AA); imshow("original", frame); // waitKey(); if (!crop.empty()) { imshow("detected", crop); // waitKey(); } else destroyWindow("detected"); }int main(int argc, char* argv[]){ faceDetection *face; face = new faceDetection; // Load the cascade face_cascade = new CascadeClassifier; if (!face_cascade->load(face_cascade_name)){ printf("--(!)Error loading\n"); return (-1); } cvNamedWindow("Camera" , CV_WINDOW_AUTOSIZE ); // 开启摄像头。 // CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); // 读取视频文件夹。 CvCapture* capture = cvCreateFileCapture("/Users/liupeng/Desktop/my/handDetection/handDetection/hand.mp4"); assert(capture != NULL); IplImage *frame = 0; while(1) { frame = cvQueryFrame(capture); if(!frame) break; face->detectAndDisplay((Mat)frame); char c = cvWaitKey(15); if(c == 27) break; } cvReleaseCapture(&capture); cvReleaseImage( &frame); return (int)0;}
0 0
- opencv_traincascade训练分类器,手势识别。
- opencv之级联分类器训练opencv_traincascade
- opencv之级联分类器训练opencv_traincascade
- opencv之利用opencv_traincascade训练分类器
- opencv级联分类器训练 opencv_traincascade
- opencv之级联分类器训练opencv_traincascade
- opencv_traincascade 训练自己的分类器
- 使用opencv_traincascade训练Haar、HOG、LBP Adaboost分类器
- 使用opencv_traincascade.exe训练分类器的注意事项
- linux下,使用opencv训练级联分类器opencv_traincascade
- 使用opencv_traincascade训练级联分类器检测手掌(一)
- OpenCV 人脸检测自学(6)opencv_traincascade如何训练强弱分类器
- 目标检测之训练opencv自带的分类器(opencv_haartraining 或 opencv_traincascade)
- opencv_traincascade 训练自己的检测器
- opencv_traincascade训练人脸检测
- 使用OPENCV训练手写数字识别分类器
- 使用OPENCV训练手写数字识别分类器
- 使用OPENCV训练手写数字识别分类器
- nodejs实时监听文件变动重启服务supervisor
- 嵌入式系统的发展特点
- 如何在eclipse上创建maven项目
- 二级指针模型之二维数组
- How to Iterate Over a Map in Java
- opencv_traincascade训练分类器,手势识别。
- 大型网站架构之系列(1)——纵观历史演变(上)
- Servlet笔记
- 1 duplicate symbol for architecture x86_64
- 第三十三讲项目4-编程序,输入10个整数,找出最大数。
- DbUtils使用说明
- WebStorm的破解
- 嵌入式系统的发展现状
- Android中的GridView的简介,配置与使用