opencv显示大图--利用鼠标在固定窗口内显示大图
2017-04-23 15:11
274 查看
opencv显示大图–利用鼠标在固定窗口内显示大图
opencv没有直接用于显示大图的函数,当显示图像大于屏幕尺寸的时候就不好显示。于是就想到利用setMouseCallback()函数来利用鼠标移动图片,效果见代码,暂时未加入放大缩小功能。#pragma execution_character_set("utf-8") #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; Mat test = imread("test.jpg"); //测试图像 void on_mouse(int event, int x, int y, int flags, void *userdata); int main() { int window_w = 800; int window_h = 800; if (!test.data) { cout << "load image failed !" << endl; return 0; } namedWindow("test", 1); Mat temp = test(Rect(0, 0, window_w, window_h)); int udata[4] = { window_w, window_h, test.cols, test.rows }; setMouseCallback("test", on_mouse, udata); imshow("test", temp); moveWindow("test", 40, 40); waitKey(); return 0; } void on_mouse(int event, int x, int y, int flags, void *userdata) { int *window_param = (int *)userdata; static int start_x = 0; static int start_y = 0; int w = *window_param; int h = *(window_param + 1); int img_w = *(window_param + 2); int img_h = *(window_param + 3); static Point ld = Point(0, 0); static Point ru = Point(0, 0); if (event == EVENT_LBUTTONDOWN) { ld = Point(x, y); } if (event == CV_EVENT_LBUTTONUP) { ru = Point(x, y); //cout << "origin:" << ld << endl; //cout << "now:" << ru << endl; start_x = (ld.x - ru.x) * 1 + start_x; start_y = (ld.y - ru.y) * 1 + start_y; start_x = start_x > (img_w - w - 1) ? (img_w - w - 1) : start_x < 0 ? 0 : start_x; start_y = start_y >(img_h - h - 1) ? (img_h - h - 1) : start_y < 0 ? 0 : start_y; //cout << start_x << endl; //cout << start_y << endl; Rect roi(start_x, start_y, w, h); Mat temp = test(roi); imshow("test", temp); } }
相关文章推荐
- 利用OpenCV鼠标控制窗口大小
- 利用OpenCV鼠标控制窗口大小
- 利用Qt的标准文件对话框及OpenCV创建窗口并显示图片
- 利用opencv将两张图像在同一窗口上显示,并在图片上显示文字
- OpenCV3.2+Qt5.8.0+Win10开发视频监控系统----(3)Qt之视频显示窗口固定
- 如何利用opencv在一个窗口显示多张图片
- Java OpenCV开发——使用JavaCV在窗口显示图像,并监听鼠标点击事件
- 如何将利用OpenCV加载的图像显示在窗口位置?
- 利用OpenCV鼠标事件设置函数setMouseCallback显示图像像素坐标值!
- 在mfc中利用opencv打开摄像头并显示在窗口上
- opencv--用鼠标动态改变显示图像窗口大小
- 解决当电脑打开比较东西后,鼠标拖动窗口会留下残影或窗口显示不了等问题
- DIV+CSS 布局一行两列,左列固定宽度,右列自适应宽度;设置最小宽度,窗口小的时候显示滚动条.
- Asp.net 利用Div固定表头+异步显示动态加载
- 完全css实现缩略图鼠标移上去显示大图
- asp.net下用js实现鼠标移至小图,自动显示相应大图
- 鼠标显示大图的效果,类似淘宝(show a enlarge image in mouse hover)
- 完全css实现缩略图鼠标移上去显示大图
- DataGrid分页;指定列的总和和平均值;显示鼠标背景色;弹出式窗口;
- 淘宝中的一个鼠标感应大图(鼠标经过显示大图)