当前位置:网站首页>6. [opencv mouse callback event]
6. [opencv mouse callback event]
2022-08-08 13:32:00 【Lee is struggling...】
鼠标操作
(一)、What is a mouse callback event and what it does?
简单的理解:The mouse callback time is when we are in the compile window,Our mouse works
And will return the two-dimensional coordinates of our mouse movement.
(二)、We need to know thoseAPI?
1.回调函数:
Functions declared outside the class、其基本格式为:
void mouse_callback(int event, int x, int y, int flag, void* userdata) //回调函数
{
cout << event << " " << x << " " << y << " " << flag << " "<< endl; //打印函数.
}
The constructor parameter format is :
event:(This article follows the basics.That is, numbers)鼠标事件
0=滑动;
1=左键点击;2=右键点击;3=China Construction Click;
4=左键放开;5=右键放开;6=右键放开;
7=左键双击;8=右键双击;9=Zhongjian double click;
x和y:鼠标指针在图像坐标系的坐标
flagsMouse key combinations are displayed:
usderata: 用户自定义参数:
2.设置鼠标回调函数:
Its name is a fixed name:SetMouseCallback(窗口名字,Callback function name,usdedata)
主要目的:is the response window.
setMouseCallback("鼠标事件", mouse_callback); //设置鼠标回调函数
(三)Operational thinking and basic thinking:
First we have to set back to the functionmousecallback;Then perform various operations of the window to print out the mouse.Then read in the image in the main function,设置窗口,Set the mouse callback function,显示帧数、Finally destroy the window.
(四)、实战项目:
1.代码展示:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void mouse_callback(int event, int x, int y, int flag, void* userdata) //回调函数
{
cout << event << " " << x << " " << y << " " << flag << " "<< endl; //打印函数.
}
int main()
{
Mat imag;
imag = imread("xx.jpg"); //读入图像
namedWindow("鼠标事件",WINDOW_NORMAL);
setMouseCallback("鼠标事件", mouse_callback); //设置鼠标回调函数
while (1)
{
imshow("鼠标事件", imag); //展示窗口
if (waitKey(25) == 27)break; //Display frame rate
}
cout << "程序退出:" << endl;
destroyAllWindows();
return 0;
}
2.效果展示:
Mouse callback event effect
边栏推荐
猜你喜欢
随机推荐
(4)FlinkSQL将socket数据写入到mysql方式一
The maximum validity period of an SSL certificate is 13 months. Is it necessary to apply for multiple years at a time?
[8月4日]剑指 Offer 52. 两个链表的第一个公共节点
C language small project -- address book (static version + dynamic version + file version)
The use of qsort function and its analog implementation
R语言ggpubr包的ggsummarystats函数可视化分面箱图(通过ggfunc参数和facet.by参数设置)、添加描述性统计结果表格、palette参数配置不同水平可视化图像和统计值的颜色
“华数杯”建模学习(Matlab)
R语言patchwork包将多个ggplot2可视化结果组合起来、使用plot_annotation函数以及tag_level参数为组合图添加自定义编码序列(字符向量列表)
leetcode 155. Min Stack最小栈(中等)
Verilog语法基础HDL Bits训练 09
牛 plus,多层嵌套动态 JSON 该如何解析总结
看到这个应用上下线方式,不禁感叹:优雅,太优雅了!
2022-08-03
程序环境和预处理
华谊“在劫难逃”,4年亏掉64亿
SSL证书最长有效期13个月,还有必要一次申请多年吗?
Jenkins - install (2)
【JS高级】ES5标准规范之严格模式下的保护对象_09
php文件上传下载(存放文件二进制到数据库)
"Huashu Cup" modeling learning (Matlab)