当前位置:网站首页>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)
边栏推荐
- Zhiniu stock -- 03
- YOLOV1学习笔记
- Pdf files can only print out the first page
- Creating postgre enterprise database by ArcGIS
- Support vector machine for machine learning
- 项目总结--2(Jsoup的基本使用)
- When PHP uses env to obtain file parameters, it gets strings
- Kubernetes notes (VI) kubernetes storage
- Page text acquisition
- ruoyi接口权限校验
猜你喜欢

Important knowledge points of redis

Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)

项目总结--01(接口的增删改查;多线程的使用)

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

Alibaba cloud OOS file upload

Tabbar settings

有意思的鼠标指针交互探究

Jedis source code analysis (II): jediscluster module source code analysis

从小数据量 MySQL 迁移数据到 TiDB

技术管理进阶——你了解成长的全貌吗?
随机推荐
Kubernetes notes (IV) kubernetes network
Alibaba cloud OOS file upload
Pdf files can only print out the first page
Kubernetes notes (10) kubernetes Monitoring & debugging
Zhiniu stock project -- 04
Naive Bayes in machine learning
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Kubernetes notes (VII) kuberetes scheduling
Common interview questions
冒泡排序的简单理解
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
YOLOV2学习与总结
How to scan when Canon c3120l is a network shared printer
Detailed explanation of contextclassloader
phpstudy设置项目可以由局域网的其他电脑可以访问
Pytorch dataloader implements minibatch (incomplete)
Apifix installation
Some thoughts on machine learning