Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update imshow() window for Python OpenCV CV2

My current program will output an image to the user and based on user input, readjust the image as necessary.

Long story short, I am trying to find circular objects in an image file. I will be using the Hough Circle Transform. However, because many of my circles in the image are not "perfect circles", I am doing an algorithm that "guesses" the radii of the circles. However, I want to allow the user to readjust the radii as necessary.

Is there some way to ask the user for input and then based on the user input, readjust the window in imshow()? Right now, imshow() refuses to show the actual window until I use cv2.waitKey(0), at which point I can't ask for user input until the window is destroyed.

like image 266
Alwin Hui Avatar asked Nov 25 '14 02:11

Alwin Hui


1 Answers

You can call imshow repeatedly without destroying it. And yes, you will likely need waitKey, just don't call it with 0 or it will wait indefinitely. Call it with a 1 to wait just 1 millisecond and ensure the image redraws. Try something like:

while True:
    cv2.imshow('image', img)
    cv2.waitKey(1)
    radius = input('Input radius')
    # recalculate image with new radius here...
like image 127
101 Avatar answered Sep 28 '22 12:09

101