当前位置:网站首页>6.【opencv鼠标回调事件】
6.【opencv鼠标回调事件】
2022-08-08 13:06:00 【李在奋斗……】
(一)、什么是鼠标回调事件以及作用?
简单的理解:鼠标回调时间就是我们在编译窗口中,我们的鼠标是可以运转的
并且会返回我们鼠标移动的二维坐标.
(二)、我们需要认识那些API?
1.回调函数:
声明在类外的函数、其基本格式为:
void mouse_callback(int event, int x, int y, int flag, void* userdata) //回调函数
{
cout << event << " " << x << " " << y << " " << flag << " "<< endl; //打印函数.
}
构造函数参数格式为:
event:(本文按照基础走。也即数字)鼠标事件
0=滑动;
1=左键点击;2=右键点击;3=中建点击;
4=左键放开;5=右键放开;6=右键放开;
7=左键双击;8=右键双击;9=中建双击;
x和y:鼠标指针在图像坐标系的坐标
flags鼠标的组合键显示:
usderata: 用户自定义参数:
2.设置鼠标回调函数:
其名称为固定的名称:SetMouseCallback(窗口名字,回调函数名字,usdedata)
主要目的:是响应窗口.
setMouseCallback("鼠标事件", mouse_callback); //设置鼠标回调函数
(三)操作思想与基本思路:
首先我们要设置回到函数mousecallback;然后进行窗口打印输出鼠标的各项操作.然后在主函数中读入图像,设置窗口,进行设置鼠标回调函数,显示帧数、最后销毁窗口.
(四)、实战项目:
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; //展示帧率
}
cout << "程序退出:" << endl;
destroyAllWindows();
return 0;
}
2.效果展示:
鼠标回调事件效果
边栏推荐
- 详解轮播图二-通过left定位来轮播图片
- Collection of shell basics
- 2022-08-03
- STM32入门开发 制作红外线遥控器(智能居家-万能遥控器)
- C language small project -- address book (static version + dynamic version + file version)
- PHP中使用XML-RPC构造Web Service简单入门
- C language small project - complete code of minesweeper game (recursive expansion + selection mark)
- MySQL的索引和事务
- The programmer essential VS debugging technique
- MeterSphere--开源持续测试平台
猜你喜欢
[C language] In-depth analysis of data storage in memory
HackTheBox | Previse
Three classic topics in C language: three-step flip method, Young's matrix, and tossing and dividing method
Docker - persistent database (data volume)
Docker-持久化数据库(数据卷)
nvm的使用 nodejs版本管理,解决用户名是汉字的问题
MySQL的索引和事务
深析C语言的灵魂 -- 指针
张一鸣挺进生育大业
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
随机推荐
腾讯,投了个 “离诺贝尔奖最近的华人”
"Huashu Cup" modeling learning (Matlab)
服务器配置——Linux系统安装Redis
R语言ggplot2可视化:基于aes函数中的fill参数和shape参数自定义绘制分组折线图并添加数据点(散点)、设置可视化图像的主题为theme_gray
C language small project - complete code of minesweeper game (recursive expansion + selection mark)
MySQL:索引(1)原理与底层结构
(7) FlinkSQL kafka data written to the mysql way 2
(6)FlinkSQL将kafka数据写入到mysql方式一
(7)FlinkSQL将kafka数据写入到mysql方式二
(8) FlinkSQL custom UDF
PE文件-手工修改重定位表-WinHex-CFF Explorer
家电行业趋势:2022从三方面把握家电产品升级方向
(5) FlinkSQL writes socket data to mysql Method 2
R语言使用位置索引筛选dataframe的数据列:筛选单个数据列、筛选多个数据列、列表表达式方法、矩阵式下标方法
Background, History and Lessons of Transfer Learning
使用.NET简单实现一个Redis的高性能克隆版(三)
论文理解:“Self-adaptive loss balanced Physics-informed neural networks“
金融行业数智化供应链管理系统:多维度评估分析供应商,赋能智能金融变革
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
Jenkins - Introduction to Continuous Integration (1)