Question

I am trying to use the function ROI in OpenCV to identify a contour, later .. in that ROI I am identifying a specific color.. so I want to draw rectangle or circle around this shape but in the original image .. the problem that the location I am retrieving is for the ROI and not the whole image .. any ideas ?

Was it helpful?

Solution

You know the offset of the ROI within the original image (say the coordinates of its top-left corner) -- just add these to the coordinates of the location within the ROI (ie where the top-left corner of the ROI is (0,0)), and that gives the location in global coordinates.

e.g.:

 ______________
|    __        |
|   |  |       |
|   |x_|       |
|______________|

Say the outer rectangle is the image, top-left corner (0,0), and the inner square is the ROI, top-left corner (1,3).

The X is the location of the thing you want to outline - it has coordinates (1,0) with respect to the square.

Add (1,0) (X coordinates with respect to ROI) to the (1,3) (ROI coordinates with respect to image) and you'll get (2,3), the coordinates of X with respect to the image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top