# Calculate image width

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

cv2.imshow("image", image)
marker = cv2.selectROI("image", image, fromCenter=False, showCrosshair=True)

print(marker)

print(marker[1]-marker[3])


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)
-178
>>>


Any tips help... Thanks

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].