当前位置:网站首页>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)
边栏推荐
- Cesium 点击获三维坐标(经纬度高程)
- Kubesphere - build MySQL master-slave replication structure
- Kubernetes notes (I) kubernetes cluster architecture
- Advanced technology management - do you know the whole picture of growth?
- Solve the problem that Anaconda environment cannot be accessed in PowerShell
- Naive Bayes in machine learning
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- . Net program configuration file operation (INI, CFG, config)
- Alibaba cloud OOS file upload
猜你喜欢
Code generator - single table query crud - generator
使用conda创建自己的深度学习环境
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
IE browser flash back, automatically open edge browser
Kubernetes notes (I) kubernetes cluster architecture
Mysql
Use abp Zero builds a third-party login module (I): Principles
Advanced technology management - do you know the whole picture of growth?
表达式的动态解析和计算,Flee用起来真香
Simple understanding of ThreadLocal
随机推荐
Tabbar settings
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
YOLOV3学习笔记
认识弹性盒子flex
Reinstalling the system displays "setup is applying system settings" stationary
Use abp Zero builds a third-party login module (I): Principles
In depth learning
Jedis source code analysis (I): jedis introduction, jedis module source code analysis
tabbar的设置
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
Zhiniu stock -- 03
Kubernetes notes (II) pod usage notes
YOLOV1学习笔记
Mysql database table export and import with binary
Migrate data from Amazon aurora to tidb
Core principles and source code analysis of disruptor
Kubernetes notes (V) configuration management
Leetcode solution - 02 Add Two Numbers
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Cesium 点击获三维坐标(经纬度高程)