Ask Your Question

selectROI does not close the window after 'enter' pressed?

asked 2019-07-16 16:57:17 -0500

ev gravatar image

updated 2019-07-17 07:11:40 -0500

supra56 gravatar image

I am using cv.selectROI twice (it was a conscious choice not to use selectROIs) and when I go to press 'enter', the second selectROI pops up but the first one does not go away. Why? selectROI should go away on its own after pressing 'space' or 'enter,' correct?

my code is like this:

img = cv.imread('image.jpg')
retval1 = cv.selectROI('select', img)
retval2 = cv.selectROI('select2', img)

I solved the problem by just using cv.destroyWindow('select') after the retval1 line. However, I shouldn't have to do that, right? Why didn't selectROI delete the window?

edit retag flag offensive close merge delete


and which language / os / opencv version are you talking about ?

berak gravatar imageberak ( 2019-07-16 23:31:35 -0500 )edit

python3-5 on ubuntu/linux with OpenCV 4

ev gravatar imageev ( 2019-07-24 12:46:19 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-07-17 10:55:44 -0500

kbarni gravatar image

Because it's not supposed to. According to the documentation:


Selects ROI on the given image. Function creates a window and allows user to select a ROI using mouse. Controls: use space or enter to finish selection, use key c to cancel selection

So pressing space simply finishes the selection, it doesn't close the window. The solution is to manually delete the window, just as you did.

edit flag offensive delete link more


Hm, usually if I use cv.selectROI() once, it automatically closes the window when I press enter or space.

ev gravatar imageev ( 2019-07-24 12:45:55 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-07-16 16:57:17 -0500

Seen: 397 times

Last updated: Jul 17 '19