Opencv人头跟踪检测
2015-11-28 20:51
651 查看
//-------------------------------------人头检测------------------------------------- int main() { //VideoCapture video("E:\\C_VC_code\\Text_Photo\\feini.flv"); vector<float>head; FILE *read = fopen("detector_TQ.txt", "r"); if (read == NULL) { cout << "Error: The file read fail" << endl; return -1; } double data; while (fscanf(read, "%lf", &data) != -1) { head.push_back(data); } cout << head.size() << endl; VideoCapture video(0); if (!video.isOpened()) { return 0; } Mat img, dstimg; vector<Rect>found; vector<Rect>result; Rect r; HOGDescriptor hog(Size(48, 48), Size(16, 16), Size(8, 8), Size(8, 8), 9); hog.setSVMDetector(head); double scalar = 0.5; int i, j; while (1) { video >> img; resize(img, dstimg, Size(img.cols*scalar, img.rows*scalar), 1, 1, 3); hog.detectMultiScale(dstimg, found, 1, cv::Size(8, 8), cv::Size(0, 0), 1.1, 3, false); //去除嵌套的矩形 result.clear(); for (i = 0; i < found.size(); i++) { r = found[i]; for (j = 0; j < found.size(); j++) { if (i != j && (r&found[j]) == r) { break; } } if (j == found.size()) { result.push_back(r); } } //draw rect for (i = 0; i<result.size(); i++) { r = result[i]; r.x = r.x/scalar*0.81; r.y = r.y/scalar; r.width = r.width/scalar*1.7; r.height = r.height/scalar*4; rectangle(img, r, CV_RGB(0, 255, 0), 2); } //imshow("video1", dstimg); imshow("video", img); found.clear(); if (waitKey(33) == 27) { imshow("video", img); waitKey(0); break; } } }
相关文章推荐
- Linux之——基础命令
- Docker镜像
- Cassandra监控 - OpsCenter手册
- 手动安装liberty版本openstack环境(allinone)---安装cinder
- Nginx配置
- Apache Stratos探究:Apache Stratos 4.1.x 的架构
- opencv的KeyPoint
- Nginx安装--2015.11.27
- Linux系统下Qt动态库的生成已经动态库的使用实例图解
- [Hadoop]HDFS shell命令
- centos7下使用yum安装mysql
- CentOS修改系统时间
- OpenCV3.0+CodeBlocks13.12环境配置
- 配置openmesh总是出现error LNK2019: 无法解析的外部符号此类问题的解决办法
- Hadoop 2.6.0动态添加节点
- Hadoop 2.6.0动态添加节点
- OpenFlow消息
- OpenGL模型视图变换、投影变换、视口变换(转载)
- 临阵磨枪,血拼季网站优化的最后三板斧
- 手动安装liberty版本openstack环境(allinone)---安装nova