[英]Cropping an image in python
I am working on an object detection project using Azure Custom Vision.我正在使用 Azure 自定义视觉进行对象检测项目。 An example of a bounding box I got is
[0.053913698, 0.6198375, 0.09218301, 0.13308609]
.我得到的边界框的一个例子是
[0.053913698, 0.6198375, 0.09218301, 0.13308609]
。
The selected answer here is not going to suit my task because all the values are less than 0. 此处选择的答案不适合我的任务,因为所有值都小于 0。
Can anyone please help?有人可以帮忙吗?
A bounding-box list tells you ["left", "top", "width", "height"]
, and each of them is in percent of the image original size .边界框列表告诉您
["left", "top", "width", "height"]
,它们中的每一个都是图像原始大小的百分比。
Assumed that your image dimension is 800 x 600 (ie, Image Width is 800, Image Height is 600).假设您的图像尺寸为 800 x 600(即图像宽度为 800,图像高度为 600)。 Therefore, what you need to do is to multiply the width and height to the corresponding values.
因此,您需要做的是将宽度和高度乘以相应的值。 Read the code below in Python:
在 Python 中阅读以下代码:
imageWidth = 800
imageHeight = 600
bbx = {
"left": 0.053913698,
"top": 0.6198375,
"width": 0.09218301,
"height": 0.13308609
}
# top-left point position
(x, y) = (bbx["left"]*imageWidth, bbx["top"]*imageHeight)
# bounding box's width and height
bbxWidth = bbx["width"] * imageWidth
bbxHeight = bbx["height"] * imageHeight
You can use the above values (ie, x
, y
, bbxWidth
, and bbxHeight
) to draw the bounding box on the original image.您可以使用上述值(即
x
、 y
、 bbxWidth
和bbxHeight
)在原始图像上绘制边界框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.