python中waitKey實例用法講解
更新時間:2021年04月23日 07:48:46 作者:小妮淺淺
在本篇文章里小編給大家整理了一篇關于python中waitKey實例用法講解,有興趣的朋友們可以參考學習下。
1、說明
用于等待按鈕。當用戶按下按鈕時,句子將被執(zhí)行并獲得返回值。
2、語法
retval=cv2.waitKey([delay])
- Retval:表示返回值;
- Delay:鍵觸發(fā)的時間,單位為ms。
3、實例
import cv2
lena=cv2.imread("D:\pmjcv\lena.bmp")
cv2.namedWindow("lesson")
cv2.imshow("lesson",lena)
key=cv2.waitKey()
實例擴展:
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import waitKeyEx [as 別名]
def on_process_messages(self, sleep_time=0):
has_windows = False
has_capture_keys = False
if len(self.named_windows) != 0:
has_windows = True
if len(self.capture_keys_windows) != 0:
has_capture_keys = True
if has_windows or has_capture_keys:
wait_key_time = max(1, int(sleep_time*1000) )
ord_key = cv2.waitKeyEx(wait_key_time)
shift_pressed = False
if ord_key != -1:
chr_key = chr(ord_key) if ord_key <= 255 else chr(0)
if chr_key >= 'A' and chr_key <= 'Z':
shift_pressed = True
ord_key += 32
elif chr_key == '?':
shift_pressed = True
ord_key = ord('/')
elif chr_key == '<':
shift_pressed = True
ord_key = ord(',')
elif chr_key == '>':
shift_pressed = True
ord_key = ord('.')
else:
if sleep_time != 0:
time.sleep(sleep_time)
if has_capture_keys and ord_key != -1:
self.add_key_event ( self.focus_wnd_name, ord_key, False, False, shift_pressed)
到此這篇關于python中waitKey實例用法講解的文章就介紹到這了,更多相關python中waitKey如何使用內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
相關文章
Python2.7基于笛卡爾積算法實現N個數組的排列組合運算示例
這篇文章主要介紹了Python2.7基于笛卡爾積算法實現N個數組的排列組合運算,涉及Python笛卡爾積算法及排列組合操作相關實現技巧,需要的朋友可以參考下2017-11-11
淺談Python3.10 和 Python3.9 之間的差異
多年來,Python 進行了大量升級,并且在新版本中添加了許多功能。本文就詳細的介紹 一下Python3.10 和 Python3.9差異,感興趣的朋友可以了解一下2021-09-09

