In this code below, a picture can be loaded into openCV and then the region of interest RIO can be created by just selecting a box around something with the mouse, then press enter.

What I am trying to do is measure the apparent width in pixels of the ROI. I am going thru some of the theory in this pyimagesearch blog post for calculating distances in images.

I have a folder called images and a .png file named 1 within the folder.

import cv2

image = cv2.imread("images/1.png")
cv2.imshow("image", image)
marker = cv2.selectROI("image", image, fromCenter=False, showCrosshair=True)



The output is below but I am not really sure how/if this can be used. I think its stating the ROI x,y height & width but I am not sure:

(317, 181, 269, 359)

Any tips help... Thanks


1 Answer 1


cv2.selectROI() returns a 2D rectangle with (x, y, width, height) (see the Rect constructor - that object is created from selectROI()).

So, if you want to measure the apparent width in pixels, you need marker[2].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.