The use of OpenCV exercises to read the picture, the picture is always a flash, is not conducive to observation, this time you need to take advantage of the waitKey function.
waitKey function: used to wait for the key to be pressed, when the user presses the key, the statement will be executed and get the return value.
The syntax format isretval=([delay])
- retval: indicates the return value;
- delay: the time to wait for the key to be triggered, in ms;
Below is a simple example demonstration:
import cv2 lena=("D:\pmjcv\") ("lesson") ("lesson",lena) key=()
Code Explanation: The second line indicates reading a picture; the third line indicates creating a window named lesson; the third line indicates displaying the read picture for the newly created window.
Then use the waitKey function to get the key pressed and react differently for different keys.
import cv2 lena=("D:\pmjcv\") ("lesson") ("lesson",lena) key=() if key == ord('A'): ("Alesson",lena) () elif key == ord('B'): ("Blesson", lena) ()
Code Explanation: When A is pressed at the keyboard, the Alesson window is displayed; when key B is pressed, the Blesson window is displayed.
When key A is pressed:
When button B is pressed:
This article on python to solve the OpenCV in the read display image flashback problem is introduced to this article, more related to OpenCV read display image flashback content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!