SoFunction
Updated on 2024-11-13

python to solve OpenCV flashback problem when reading display images

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!