2

I have the coordinates values of an image as:

tl = (result['topleft']['x'], result['topleft']['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])

I would like to crop the original image (of sizes [720,720,3]) around that area of interest; what is the correct formula?

I have found this one:

crop_img = imgcv[y:y+h, x:x+w]

But I struggle to put the right values of the coordinate system in it;

1 Answer 1

4

crop_img = imgcv[y:y+h, x:x+w] is a correct formula to do it if you have a rectangle, i.e. the top left point and the width and height of the rectangle, but you can do it directly since you have the top left and bottom right points.

crop_img = imgcv[tl[1]:br[1], tl[0]:br[0]]

basically the formula tells from:to first in y coordinates and then in x coordinates. Since the top left point of the image is the origin, then its coordinates is the from and the bottom right coordinates is the to

If you have any doubt, leave a comment

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.