当前位置:网站首页>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)
边栏推荐
- 从小数据量分库分表 MySQL 合并迁移数据到 TiDB
- Luogu problem list: [mathematics 1] basic mathematics problems
- pytorch练习小项目
- Cesium entity (entities) entity deletion method
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Kubernetes notes (I) kubernetes cluster architecture
- Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
- MySQL帶二進制的庫錶導出導入
- IE browser flash back, automatically open edge browser
- Kubesphere - set up redis cluster
猜你喜欢
随机推荐
代码管理工具
Selenium ide installation recording and local project maintenance
堆排序和优先队列
Push box games C #
数值法求解最优控制问题(一)——梯度法
Migrate data from Mysql to tidb from a small amount of data
Use abp Zero builds a third-party login module (I): Principles
Floating menu operation
Shell conditional statement
ssh链接远程服务器 及 远程图形化界面的本地显示
智牛股项目--04
YOLOV2学习与总结
表达式的动态解析和计算,Flee用起来真香
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
Migrate data from Amazon aurora to tidb
【5G NR】UE注册流程
Common interview questions
Interesting research on mouse pointer interaction
Cannot get value with @value, null
Decision tree of machine learning









