如何根据边界框值计算 x,y 坐标

How to calculate x,y coordinates from bounding box values

我想使用 java 中的 BufferedImage.getSubimage(x,y,width,height) 函数使用其 x,y 坐标裁剪图像。但是我只有图像的边界框来裁剪它的一部分。

如何使用 java 从边界框获取 x、y 坐标?有计算方法吗?

我正在给边界框值 (xMin,yMin,xMax,yMax)(0.46476197,0.46967554,0.8502463,0.67080903 )

How can i get x,y coordinates from bounding box using java? Is there any calculation available?

如果您计算出的边界框坐标对应于图像分数,您首先必须计算 xMin、xMax、yMin 和 yMax 的像素值。

使用这些可以很容易地计算函数的必要参数BufferedImage.getSubimage(x,y,width,height)

x和y对应边界框的左上角,因此:

x = xMiny = yMin

框的宽度可以使用图像宽度减去左 space 通向框的长度以及右 space 框结束处的长度来计算,因此您可以使用公式计算:

width = imageWidth - xMin - (imageWidth - xMax)

高度也一样,只需使用 y 坐标即可:

height = imageHeight - yMin - (imageHeight - yMax)

I am multiplying bounding box values with image width and height respectively to get its pixel values. 

int y1 = yMin * ImageHeight;
int x1 = xMin * ImageWidth;
int y2 = yMax * ImageHeight;
int x2 = xMax * ImageWidth;

And applied the values to below given formula

BufferedImage.getSubimage((int)x1, (int)y1, (x2-x1), (y2-y1));

Thanks gilbert for giving solution to get pixel values.