opencv2在视频帧序列中运用鼠标extract rectangle region
来源:互联网 发布:北大青鸟网络课程介绍 编辑:程序博客网 时间:2024/06/11 21:26
Refer from http://blog.csdn.net/qq_23880193/article/details/41974849
刚刚写好的在图像中运用鼠标事件,现在要写的是在视频序列中运用鼠标事件
- #include<opencv2/imgproc/imgproc.hpp>
- #include<opencv2/imgproc/types_c.h>
- #include<opencv2/highgui/highgui.hpp>
- #include<opencv2/core/core.hpp>
- #include<iostream>
- #include<vector>
- #include<opencv2/nonfree/features2d.hpp>
- #include<opencv2/legacy/legacy.hpp>
- #include<opencv2/features2d/features2d.hpp>
- #include<opencv2/calib3d/calib3d.hpp>
- #include<opencv2/video/tracking.hpp>
- using namespace cv;
- using namespace std;
- Point coord;//储存初始坐标
- Rect sqart;//储存矩形框的起始坐标以及长度和宽度
- bool draw;
- bool flag = 0;//这个标志位是用在如果要将矩形标定的部分单独显示在一个窗口时使用的
- Mat frame;
- Mat dst;//感兴趣区域图像
- void onMouse(int event, int x, int y, int flags, void *param)
- {
- //显示鼠标的当前坐标
- cout << "Event:" << event << endl;
- cout << "x=" << x << " " << "y=" << y << endl;
- cout << "flags:" << endl;
- cout << "param" << param << endl;
- //这个if必须放在switch之前
- if (draw)
- {
- //用MIN得到左上点作为矩形框的其实坐标,如果不加这个,画矩形时只能向一个方向进行
- sqart.x = MIN(x, coord.x);
- sqart.y = MIN(y, coord.y);
- sqart.width = abs(coord.x - x);
- sqart.height = abs(coord.y - y);
- //防止矩形区域超出图像的范围
- sqart &= Rect(0, 0, frame.cols, frame.rows);
- }
- switch (event)
- {
- case CV_EVENT_LBUTTONDOWN:
- coord = Point(x, y);
- sqart = Rect(x, y, 0, 0);
- draw = true;
- break;
- case CV_EVENT_LBUTTONUP:
- draw = false;
- flag = 1;
- break;
- }
- }
- int main()
- {
- char c;
- VideoCapture capture(0);
- namedWindow("Mouse", 1);
- setMouseCallback("Mouse", onMouse, 0);
- //由于视频序列的每一帧都在跟新,所以不会出现连环嵌套的状况
- while (1)
- {
- capture >> frame;
- if (frame.empty())
- return -1;
- //将矩形框得到矩形区域用另一个窗口显示
- if ((flag == 1) && sqart.height > 0 && sqart.width > 0)
- {
- dst = frame(Rect(sqart.x, sqart.y, sqart.width, sqart.height));
- namedWindow("dst");
- imshow("dst", dst);
- flag = 0;
- }
- rectangle(frame, sqart, Scalar(0, 0, 255), 3);
- imshow("Mouse", frame);
- c = waitKey(20);
- if (c == 27)
- break;
- }
- return 0;
- }
- 以上程序是以打开摄像头为例的,由于没有好的背景,下面的截图是用的一个视频段截出来的结果,程序中只要把capture.open(0)改为capture.open(视频路径)即可。
0 0
- opencv2在视频帧序列中运用鼠标extract rectangle region
- opencv2在视频帧序列中运用鼠标事件
- opencv2对图像运用鼠标事件
- opencv2在MFC对话框控件中显示图片播放视频
- OPENCV2 中视频处理——用鼠标选定矩形框并实时处理显示
- 关于opencv2中鼠标响应操作
- opencv2 circle rectangle
- OpenCV2编程手册笔记之 10.2读取视频序列
- 在C#中,#region的作用
- 在C#中,#region的作用
- 在MFC中,运用轨迹球算法实现鼠标旋转物体
- 在VS2010+OpenCV2.3.1控制台应用程序实现鼠标点击操作
- 序列计数定时器在游戏中的运用
- Flash视频播放器 JW PLAYER怎么在网页中运用?
- Extract User Defined Region From An Chromosome Fasta File
- 算法-有序序列中运用“压缩”思想
- Opencv2.4.9鼠标操作
- oracle中extract()函数
- 数据结构--remove方法对LinkedList类的使用注意
- HDU 3887 Counting Offspring(dfs序的应用)
- Ubuntu下安装cgal4.5.2计算几何库
- Adobe Photoshop CS6提示”无法完成请求,因为文件格式模块不能解析该文件“
- 几个项目规划畅想etc.
- opencv2在视频帧序列中运用鼠标extract rectangle region
- 自学数据挖掘十大算法之PageRank
- LeetCode: Rotate Array
- 3.5学习内容 宽带测速原理,RESTful架构,rpc个人理解
- 增强现实追加2
- innodb优化转载篇
- 利用citeUlike管理文献
- 新的一年飘了一下,就过来了. 在过去的一年,大家都找到了自已的幸福吗?
- LeetCode之Multiply Strings