關(guān)于python下cv.waitKey無(wú)響應(yīng)的原因及解決方法
按下鍵的時(shí)候,焦點(diǎn)要落在窗口上,不能落在cmd窗口上。
另外,一般在imshow()后要使用waitKey(),給圖像繪制留下時(shí)間,不然窗口會(huì)出現(xiàn)無(wú)響應(yīng)情況,并且圖像無(wú)法顯示出來(lái)。
int waitKey(int delay=0)
- 延時(shí)delay = 0 函數(shù)則延時(shí)無(wú)限長(zhǎng),必須有鍵按下才繼續(xù)執(zhí)行。
- 延時(shí)delay > 0 函數(shù)返回值為按下的鍵的ASCII碼值,超時(shí)則返回-1。
OpenCV: waitKey
waitKey
Waits for a pressed key.
C++: int waitKey(int delay=0)
Python: cv2.waitKey([delay]) → retval
Parameters: delay – Delay in milliseconds. 0 is the special value that means “forever”.
The function waitKey waits for a key event infinitely (when \texttt{delay}\leq 0 ) or for delay milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is running on your computer at that time. It returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.
Note
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.
Note
The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.
也就是說(shuō)必須在有窗口顯示的情況下,waitKey才有作用,否則無(wú)效。
比如調(diào)用cv.waitKey(0),如果此時(shí)沒(méi)有活動(dòng)的窗口,該函數(shù)立刻返回-1
以上這篇關(guān)于python下cv.waitKey無(wú)響應(yīng)的原因及解決方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python 利用openpyxl讀取Excel表格中指定的行或列教程
這篇文章主要介紹了python 利用openpyxl讀取Excel表格中指定的行或列教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-02-02
pyqt5 實(shí)現(xiàn)多窗口跳轉(zhuǎn)的方法
今天小編就為大家分享一篇pyqt5 實(shí)現(xiàn)多窗口跳轉(zhuǎn)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-06-06
python學(xué)習(xí)筆記之列表(list)與元組(tuple)詳解
List(列表)是Python中使用最頻繁的數(shù)據(jù)類型,而元組是另一個(gè)數(shù)據(jù)類型,類似于List(列表)。這篇文章主要給大家介紹了python學(xué)習(xí)筆記之列表(list)與元組(tuple)的相關(guān)資料,文中不僅詳細(xì)介紹了兩者的使用,還分享了list和tuple的相互轉(zhuǎn)換的方法,需要的朋友可以參考下2017-11-11
django model的update時(shí)auto_now不被更新的原因及解決方式
這篇文章主要介紹了django model的update時(shí)auto_now不被更新的原因及解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
Python動(dòng)態(tài)生成多維數(shù)組的方法示例
這篇文章主要介紹了Python動(dòng)態(tài)生成多維數(shù)組的方法,涉及Python數(shù)組動(dòng)態(tài)遍歷、添加、打印等相關(guān)操作技巧,需要的朋友可以參考下2018-08-08

