Skip to content
Advertisement

Drawing a simple image, displaying it, and closing it

I am trying to do some simple drawings. I wanted to use opencv (cv2) because on a second project I have to display a small animation (rectangle, size depending on a variable; updated every X seconds). However, I do not have experience with image processing libraries and opencv.

I am running into a lot of problems, one of which is that I do not know how to display/close images. The image I am creating is a simple fixation cross, black; on a light gray background:

JavaScript

N.B: If there is a better way to create it, I am also interested :)

My goal is for this first project to do have the following code structure:

JavaScript

I know I can add text with cv2.putText() and that I can this way create a second image with the text. What I do not know is how can I manage the displaying of the different images; especially in a light-weight fashion while “doing stuff” on the background. Most people seems to use cv2.waitKey() which is not suited since I do not want to have any user input and since it seems to be something similar to a time.sleep() during which the program is basically paused.

Any tips welcome, even on other libraries and implementation :)

Advertisement

Answer

As proposed by @Miki, the combination of .imshow() and .waitKey(1) is working.

JavaScript

However, those can not be used with time.sleep() to pause the program. Sometimes, the display will not be updated. For instance, on a 3 second countdown:

JavaScript

Sometimes one of the displays will be skipped. Instead, changing the parameter of cv2.waitKey() to 1000 (timer needed) and removing the use of the time module works best, if no keyboard input is expected during this time.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement