How to update imshow () window for Python OpenCV CV2

My current program will output the image to the user and based on the user input, adjust the image as needed.

Long story short, I am trying to find circular objects in an image file. I will use a circular motion transform. However, since 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 the user to be able to adjust the radii as needed.

Is there a way to prompt the user for input and then based on the user input, adjust the window in imshow ()? Right now imshow () refuses to show the actual window until I use cv2.waitKey (0), after which I cannot prompt for user input until the window is destroyed.

+3


source to share


1 answer


You can call imshow

multiple times without destroying it. And yes, you will most likely need it waitKey

, just don't call it 0 or it will wait forever. Name it 1 to wait just 1ms and make sure the image is redrawn. Try something like:



while True:
    cv2.imshow('image', img)
    cv2.waitKey(1)
    radius = input('Input radius')
    # recalculate image with new radius here...

      

+6


source







All Articles