当前位置:网站首页>opencv鼠标键盘事件
opencv鼠标键盘事件
2022-07-03 06:15:00 【fksfdh】
1、窗口循环读取
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、获取键盘值
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、鼠标
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("鼠标左键按下,位置({},{})".format(x,y))
elif event == cv2.EVENT_LBUTTONUP:
print("鼠标左键抬起,位置({},{})".format(x,y))
elif event == cv2.EVENT_LBUTTONDBLCLK:
print("鼠标左键双击,位置({},{})".format(x,y))
elif event == cv2.EVENT_RBUTTONDOWN:
print("鼠标右键按下,位置({},{})".format(x,y))
elif event == cv2.EVENT_RBUTTONUP:
print("鼠标右键抬起,位置({},{})".format(x, y))
elif event == cv2.EVENT_RBUTTONDBLCLK:
print("鼠标右键双击,位置({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONDOWN:
print("鼠标滚轮按下,位置({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONUP:
print("鼠标滚轮抬起,位置({},{})".format(x, y))
elif event == cv2.EVENT_MBUTTONDBLCLK:
print("鼠标滚轮双击,位置({},{})".format(x, y))
elif event == cv2.EVENT_MOUSEMOVE:
print("鼠标移动,位置({},{})".format(x, y))
cv2.namedWindow("mouse event")
cv2.setMouseCallback("mouse event",on_mouse)
cv2.waitKey(0)
边栏推荐
- 项目总结--2(Jsoup的基本使用)
- Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
- Cesium entity(entities) 实体删除方法
- ODL framework project construction trial -demo
- Understand the first prediction stage of yolov1
- Kubesphere - build Nacos cluster
- 技术管理进阶——你了解成长的全貌吗?
- In depth analysis of kubernetes controller runtime
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
猜你喜欢

Kubesphere - Multi tenant management

使用 Abp.Zero 搭建第三方登录模块(一):原理篇

Convolution operation in convolution neural network CNN

Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency

Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow

智牛股--03

Cesium 点击获取模型表面经纬度高程坐标(三维坐标)

Analysis of Clickhouse mergetree principle

YOLOV1学习笔记
![[system design] proximity service](/img/4a/2e68536cbe385af1d1a591e674fbf0.png)
[system design] proximity service
随机推荐
Mysql database table export and import with binary
Kubernetes notes (VIII) kubernetes security
Important knowledge points of redis
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
项目总结--01(接口的增删改查;多线程的使用)
[system design] proximity service
Oracle database synonym creation
Analysis of Clickhouse mergetree principle
The mechanical hard disk is connected to the computer through USB and cannot be displayed
Kubesphere - build Nacos cluster
phpstudy设置项目可以由局域网的其他电脑可以访问
Redis cluster creation, capacity expansion and capacity reduction
Some thoughts on machine learning
JMeter performance automation test
从小数据量 MySQL 迁移数据到 TiDB
Use abp Zero builds a third-party login module (I): Principles
ODL framework project construction trial -demo
Migrate data from Mysql to tidb from a small amount of data
使用conda创建自己的深度学习环境
Get a screenshot of a uiscrollview, including off screen parts