Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do OpenCV's selectROI coordinates work?

I need to use the selectROI function for my project. However, I just can’t seem to wrap my head around the format of the coordinates. According to this link, the coordinate array should be in this form: [Top_X, Top_Y, Bottom_X, Bottom_Y]. Assuming that the top left corner starts at (0,0) for (x,y), why are my coordinates so off when I draw 3 different bounding boxes using the selectROI function?

This is what I used to create my bounding boxes and output the coordinates:

import cv2

image = cv2.imread("path")

# Select ROI
r = cv2.selectROI("select the area", image, fromCenter=False)

print('Selected bounding boxes: {}'.format(r))

The following were outputted (see the image for reference of the boxes):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

box 1: (42, 18, 212, 303)
box 2: (463, 314, 108, 226)
box 3: (1215, 801, 79, 161)
image

Why do the x-values increase from 42 -> 212 -> 464 -> back to 108 -> 1125 -> back to 79… shouldn’t the coordinates for the x’s be increasing? And same goes for the y.

>Solution :

The explanation on geeksforgeeks is wrong or at least easy to misunderstand: the last two values are not coordinates for the bottom-right corner, they are width and height of the rectangle. Notice that e.g. for the third rectangle, the height (161) is roughly twice the width (79), which matches the appearance of the rectangle.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading