您好,登錄后才能下訂單哦!
小編給大家分享一下python下cv.waitKey無響應的原因是什么,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
按下鍵的時候,焦點要落在窗口上,不能落在cmd窗口上。
另外,一般在imshow()后要使用waitKey(),給圖像繪制留下時間,不然窗口會出現無響應情況,并且圖像無法顯示出來。
int waitKey(int delay=0) - 延時delay = 0 函數則延時無限長,必須有鍵按下才繼續執行。 - 延時delay > 0 函數返回值為按下的鍵的ASCII碼值,超時則返回-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.
也就是說必須在有窗口顯示的情況下,waitKey才有作用,否則無效。
比如調用cv.waitKey(0),如果此時沒有活動的窗口,該函數立刻返回-1
以上是“python下cv.waitKey無響應的原因是什么”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。