简体   繁体   English

使用 OpenCV 坐标裁剪图像

[英]Crop an image using OpenCV Coordinates

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;我想在感兴趣的区域周围裁剪原始图像(大小为 [720,720,3]); 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;但是我很难将坐标系的正确值放入其中;

crop_img = imgcv[y:y+h, x:x+w] is a correct formula to do it if you have a rectangle, ie 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[y:y+h, x:x+w]是一个正确的公式,如果你有一个矩形,即左上角和矩形的宽度和高度,但你可以直接做,因为你有左上角和右下角的点。

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.基本上公式告诉from:to首先在 y 坐标中,然后在 x 坐标中。 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由于左上方的图像的点为原点,那么它的坐标是from和右下角的坐标是to

If you have any doubt, leave a comment如果您有任何疑问,请发表评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM