当前位置:网站首页>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
边栏推荐
- R语言ggplot2可视化:基于aes函数中的fill参数和shape参数自定义绘制分组折线图并添加数据点(散点)、设置可视化图像的主题为theme_gray
- R语言ggplot2可视化:使用ggpubr包的ggline函数可视化折线图(点线图、line plot)、设置add参数为mean可视化不同水平均值的折线图
- R语言ggpubr包的ggsummarystats函数可视化分面箱图(通过ggfunc参数和facet.by参数设置)、添加描述性统计结果表格、palette参数配置不同水平可视化图像和统计值的颜色
- MySQL:索引(1)原理与底层结构
- 五面阿里巴巴拿offer后定级P6:分享自己的面试经历
- Doris学习笔记之优化
- shell基础知识合集
- C语言小项目 -- 通讯录(静态版+动态版+文件版)
- 【第2天】SQL快速入门-条件查询(SQL 小虚竹)
- 什么是IP SSL证书,如何申请?
猜你喜欢
随机推荐
MySQl表的增删查改(CRUD)
“华数杯”建模学习(Matlab)
MySQL:索引(1)原理与底层结构
logistic回归模型—基于R
Kotlin系列之let、with、run、apply、also函数的使用
Knowledge points and written test questions related to shift operations, bit operations, and logical operations
SQL的INSERT INTO和INSERT INTO SELECT语句
C语言的三个经典题目:三步翻转法、杨氏矩阵、辗转相除法
【软考 系统架构设计师】软件架构设计⑦ 构件与中间件技术
行业领先的界面开发组件DevExpress 8月发布新版——v22.1.4
连锁小酒馆第一股,海伦司能否梦圆大排档?
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
服务器配置——Linux系统安装Redis
深入浅出对话系统——任务型对话系统技术框架
《预训练周刊》第56期:长文本理解、即时问答、掩码自监督
SSTI漏洞介绍认识(flask、Werkzeup)
Background, History and Lessons of Transfer Learning
字符串函数、字符函数、内存函数的使用及其模拟实现
优刻得“失速”:营收转降,定向增发股东浮亏超三成
南非 KMP 媒体集团实施了 DMS(文档管理系统)使流程数字化,员工可以再次专注于他们的实际任务,提供了效率