当前位置:网站首页>Opencv mouse and keyboard events
Opencv mouse and keyboard events
2022-07-03 06:23:00 【fksfdh】
1、 Window cycle read
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
from itertools import cycle
filename = os.listdir("../images")
img_iter = cycle([cv2.imread(os.sep.join(["../images",x]))for x in filename])
key = 0
while key != 27:
cv2.imshow("img",next(img_iter))
key = cv2.waitKey(42)
2、 Get keyboard value
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
from itertools import cycle
img = cv2.imread("../images/img.jpg")
key = 0
while key != 27:
cv2.imshow("img",img)
key = cv2.waitKey()
msg = "{} if pressed!".format(chr(key) if key < 256 else key)
print(msg)
3、 mouse
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
from itertools import cycle
def on_mouse(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDOWN:
print(" Press the left mouse button , Location ({},{})".format(x,y))
elif event == cv2.EVENT_LBUTTONUP:
print(" Left mouse button raised , Location ({},{})".format(x,y))
elif event == cv2.EVENT_LBUTTONDBLCLK:
print(" Double click with the left mouse button , Location ({},{})".format(x,y))
elif event == cv2.EVENT_RBUTTONDOWN:
print(" Press the right mouse button , Location ({},{})".format(x,y))
elif event == cv2.EVENT_RBUTTONUP:
print(" Right click to lift up , Location ({},{})".format(x, y))
elif event == cv2.EVENT_RBUTTONDBLCLK:
print(" Double click with the right mouse button , Location ({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONDOWN:
print(" Press the mouse wheel , Location ({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONUP:
print(" Lift the mouse wheel , Location ({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONDBLCLK:
print(" Double click the mouse wheel , Location ({},{})".format(x, y))
elif event == cv2.EVENT_MOUSEMOVE:
print(" Mouse movement , Location ({},{})".format(x, y))
cv2.namedWindow("mouse event")
cv2.setMouseCallback("mouse event",on_mouse)
cv2.waitKey(0)
边栏推荐
- Interesting research on mouse pointer interaction
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
- Une exploration intéressante de l'interaction souris - pointeur
- Mysql5.7 group by error
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- Common interview questions
- YOLOV1学习笔记
- Some thoughts on machine learning
- Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
- About the difference between count (1), count (*), and count (column name)
猜你喜欢

Selenium ide installation recording and local project maintenance

Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface

10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”

Kubernetes notes (IV) kubernetes network

Kubernetes notes (VI) kubernetes storage

技术管理进阶——你了解成长的全貌吗?

ssh链接远程服务器 及 远程图形化界面的本地显示

SQL实现将多行记录合并成一行

Use abp Zero builds a third-party login module (I): Principles

使用conda创建自己的深度学习环境
随机推荐
Use selenium to climb the annual box office of Yien
Mysql database table export and import with binary
Kubernetes notes (III) controller
JMeter performance automation test
Support vector machine for machine learning
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
Common interview questions
opencv鼠标键盘事件
Shell conditional statement
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
剖析虚幻渲染体系(16)- 图形驱动的秘密
【5G NR】UE注册流程
Oracle Database Introduction
Kubernetes notes (V) configuration management
有意思的鼠标指针交互探究
Printer related problem record
Read blog type data from mysql, Chinese garbled code - solved
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
方差迭代公式推导