当前位置:网站首页>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)
边栏推荐
- YOLOV3学习笔记
- Leetcode problem solving summary, constantly updating!
- Read blog type data from mysql, Chinese garbled code - solved
- Chapter 8. MapReduce production experience
- Naive Bayes in machine learning
- Interesting research on mouse pointer interaction
- Push box games C #
- Mysql5.7 group by error
- Leetcode solution - 01 Two Sum
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
猜你喜欢

Scripy learning

Es remote cluster configuration and cross cluster search

Redis cluster creation, capacity expansion and capacity reduction

Migrate data from Mysql to tidb from a small amount of data

Simple solution of small up main lottery in station B

phpstudy设置项目可以由局域网的其他电脑可以访问

ruoyi接口权限校验

ROS+Pytorch的联合使用示例(语义分割)

Zhiniu stock -- 03

Kubernetes notes (VI) kubernetes storage
随机推荐
从小数据量 MySQL 迁移数据到 TiDB
Project summary --04
Kubernetes notes (VI) kubernetes storage
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Mysql database
ROS+Pytorch的联合使用示例(语义分割)
YOLOV2学习与总结
Leetcode problem solving summary, constantly updating!
Print time Hahahahahaha
【系统设计】邻近服务
Oauth2.0 - use database to store client information and authorization code
scroll-view指定滚动元素的起始位置
Oracle database synonym creation
arcgis创建postgre企业级数据库
Migrate data from Mysql to tidb from a small amount of data
Exportation et importation de tables de bibliothèque avec binaires MySQL
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
PMP笔记记录
ssh链接远程服务器 及 远程图形化界面的本地显示