当前位置:网站首页>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)
边栏推荐
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
- Creating postgre enterprise database by ArcGIS
- Scripy learning
- Simple understanding of ThreadLocal
- PHP用ENV获取文件参数的时候拿到的是字符串
- Request weather interface format, automation
- Use abp Zero builds a third-party login module (I): Principles
- 致即将毕业大学生的一封信
- The mechanical hard disk is connected to the computer through USB and cannot be displayed
- Support vector machine for machine learning
猜你喜欢
tabbar的设置
Oauth2.0 - Introduction and use and explanation of authorization code mode
Docker advanced learning (container data volume, MySQL installation, dockerfile)
Push box games C #
JMeter performance automation test
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
Kubernetes notes (I) kubernetes cluster architecture
Oauth2.0 - explanation of simplified mode, password mode and client mode
phpstudy设置项目可以由局域网的其他电脑可以访问
Use selenium to climb the annual box office of Yien
随机推荐
Virtual memory technology sharing
Kubernetes notes (IX) kubernetes application encapsulation and expansion
YOLOV2学习与总结
技术管理进阶——你了解成长的全貌吗?
Install VM tools
Common interview questions
Method of converting GPS coordinates to Baidu map coordinates
深入解析kubernetes controller-runtime
scroll-view指定滚动元素的起始位置
Characteristics and isolation level of database
Interesting research on mouse pointer interaction
Creating postgre enterprise database by ArcGIS
堆排序和优先队列
opencv
MATLAB如何修改默认设置
Oauth2.0 - using JWT to replace token and JWT content enhancement
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
Request weather interface format, automation
Kubernetes notes (10) kubernetes Monitoring & debugging
Mysql database table export and import with binary