peopledetect.cpp demo
2014-05-25 20:14
302 查看
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include <stdio.h> #include <string.h> #include <ctype.h> using namespace cv; using namespace std; void help() { printf( "\nDemonstrate the use of the HoG descriptor using\n" " HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\n" "Usage:\n" "./peopledetect (<image_filename> | <image_list>.txt)\n\n"); } int main(int argc, char** argv) { Mat img; FILE* f = 0; char _filename[1024]; if( argc == 1 ) { printf("Usage: peopledetect (<image_filename> | <image_list>.txt)\n"); return 0; } img = imread(argv[1]); if( img.data ) { strcpy(_filename, argv[1]); } else { f = fopen(argv[1], "rt"); if(!f) { fprintf( stderr, "ERROR: the specified file could not be loaded\n"); return -1; } } HOGDescriptor hog; hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); namedWindow("people detector", 1); for(;;) { char* filename = _filename; if(f) { if(!fgets(filename, (int)sizeof(_filename)-2, f)) break; //while(*filename && isspace(*filename)) // ++filename; if(filename[0] == '#') continue; int l = strlen(filename); while(l > 0 && isspace(filename[l-1])) --l; filename[l] = '\0'; img = imread(filename); } printf("%s:\n", filename); if(!img.data) continue; fflush(stdout); vector<Rect> found, found_filtered; double t = (double)getTickCount(); // run the detector with default parameters. to get a higher hit-rate // (and more false alarms, respectively), decrease the hitThreshold and // groupThreshold (set groupThreshold to 0 to turn off the grouping completely). hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2); t = (double)getTickCount() - t; printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency()); size_t i, j; for( i = 0; i < found.size(); i++ ) { Rect r = found[i]; for( j = 0; j < found.size(); j++ ) if( j != i && (r & found[j]) == r) break; if( j == found.size() ) found_filtered.push_back(r); } for( i = 0; i < found_filtered.size(); i++ ) { Rect r = found_filtered[i]; // the HOG detector returns slightly larger rectangles than the real objects. // so we slightly shrink the rectangles to get a nicer output. r.x += cvRound(r.width*0.1); r.width = cvRound(r.width*0.8); r.y += cvRound(r.height*0.07); r.height = cvRound(r.height*0.8); rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3); } imshow("people detector", img); int c = waitKey(0) & 255; if( c == 'q' || c == 'Q' || !f) break; } if(f) fclose(f); return 0; }
相关文章推荐
- 当OpenCV编译遇到"无法解析的外部符号"时(编译peopledetect.cpp)
- opencv 自带文件 peopledetect.cpp 中 HOGDescriptor hog出错,解决方法
- 利用opencv自带detectpeople.cpp进行行人检测
- 【JSONCpp】简介及demo
- Qt jsoncpp 对象拷贝、删除、函数调用 demo
- QT Demo 之 calqlatr(1) main.cpp
- 用ORL人脸数据库和opencv的facererc_demo.cpp做人脸检测
- 计算机视觉caffe之路第五篇:关于ssd_detect.cpp的使用方法
- opencv内demo(find_obj.cpp)理解
- face_detect_demo()
- cocos2d-x TestCpp 中的Sprite的demo讲解
- TLD(track-learning-detect) 相关的资源下载(包含demo.zip,MCR 7.13, slides)
- opencv face detect demo (转载)
- 【JSONCpp】简介及demo
- cpp-tests ClippingNodeTest--HoleDemo
- cpp-tests ClippingNodeTest--ScrollViewDemo、ShapeTest等
- 10-Thrift_Cpp_Win编译+Demo
- asm_demo.cpp
- QT DEMO编译错误问题解决:arthurwidgets.cpp:54:35: error: 和gluPerspective未定义问题.
- 关于demo.cpp:(.text.startup+0x8f): undefined reference to `vtable for SlotObject' ,问题探究