当前位置:网站首页>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)
边栏推荐
- PMP notes
- 【系统设计】邻近服务
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
- Simple understanding of ThreadLocal
- Detailed explanation of contextclassloader
- Support vector machine for machine learning
- Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
- Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
- Tabbar settings
- Pytorch builds the simplest version of neural network
猜你喜欢

Mysql

Pytorch builds the simplest version of neural network

Kubernetes notes (II) pod usage notes

Detailed explanation of contextclassloader

Core principles and source code analysis of disruptor

Important knowledge points of redis

项目总结--2(Jsoup的基本使用)

Zhiniu stock project -- 05

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

Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
随机推荐
Detailed explanation of findloadedclass
Docker advanced learning (container data volume, MySQL installation, dockerfile)
Scripy learning
Tabbar settings
What's the difference between using the Service Worker Cache API and regular browser cache?
Shell conditional statement
Alibaba cloud OOS file upload
PMP notes
Leetcode problem solving summary, constantly updating!
BeanDefinitionRegistryPostProcessor
Difference between shortest path and minimum spanning tree
Cesium entity(entities) 实体删除方法
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Disruptor learning notes: basic use, core concepts and principles
Alibaba cloud Alipay sandbox payment
Kubesphere - build Nacos cluster
Kubesphere - set up redis cluster
Cannot get value with @value, null
Push box games C #
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)