python中waitKey實(shí)例用法講解
更新時(shí)間:2021年04月23日 07:48:46 作者:小妮淺淺
在本篇文章里小編給大家整理了一篇關(guān)于python中waitKey實(shí)例用法講解,有興趣的朋友們可以參考學(xué)習(xí)下。
1、說明
用于等待按鈕。當(dāng)用戶按下按鈕時(shí),句子將被執(zhí)行并獲得返回值。
2、語法
retval=cv2.waitKey([delay])
- Retval:表示返回值;
- Delay:鍵觸發(fā)的時(shí)間,單位為ms。
3、實(shí)例
import cv2 lena=cv2.imread("D:\pmjcv\lena.bmp") cv2.namedWindow("lesson") cv2.imshow("lesson",lena) key=cv2.waitKey()
實(shí)例擴(kuò)展:
# 需要導(dǎo)入模塊: 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)
到此這篇關(guān)于python中waitKey實(shí)例用法講解的文章就介紹到這了,更多相關(guān)python中waitKey如何使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python的條件表達(dá)式和lambda表達(dá)式實(shí)例
今天小編就為大家分享一篇Python的條件表達(dá)式和lambda表達(dá)式實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-01-01手把手教你實(shí)現(xiàn)Python重試超時(shí)裝飾器
這篇文章主要為大家介紹了實(shí)現(xiàn)Python重試超時(shí)裝飾器教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2023-05-05Python2.7基于笛卡爾積算法實(shí)現(xiàn)N個(gè)數(shù)組的排列組合運(yùn)算示例
這篇文章主要介紹了Python2.7基于笛卡爾積算法實(shí)現(xiàn)N個(gè)數(shù)組的排列組合運(yùn)算,涉及Python笛卡爾積算法及排列組合操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-11-11淺談Python3.10 和 Python3.9 之間的差異
多年來,Python 進(jìn)行了大量升級,并且在新版本中添加了許多功能。本文就詳細(xì)的介紹 一下Python3.10 和 Python3.9差異,感興趣的朋友可以了解一下2021-09-09