返回边界框的坐标谷歌的对象检测 API [英] Return coordinates for bounding boxes Google's Object Detection API

查看:58
本文介绍了返回边界框的坐标谷歌的对象检测 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Google 的对象检测 API 的推理脚本获取生成的边界框的坐标?我知道打印 box[0][i] 返回图像中第 i 个检测的预测,但这些返回数字的确切含义是什么?有没有办法让我得到 xmin,ymin,xmax,ymax?提前致谢.

How can i get the coordinates of the produced bounding boxes using the inference script of Google's Object Detection API? I know that printing boxes[0][i] returns the predictions of the ith detection in an image but what exactly is the meaning of these returned numbers? Is there a way that i can get xmin,ymin,xmax,ymax? Thanks in advance.

推荐答案

Google 对象检测 API 以 [ymin, xmin, ymax, xmax] 格式和规范化形式返回边界框(完整说明 此处).要找到 (x,y) 像素坐标,我们需要将结果乘以图像的宽度和高度.首先获取图像的宽度和高度:

Google Object Detection API returns bounding boxes in the format [ymin, xmin, ymax, xmax] and in normalised form (full explanation here). To find the (x,y) pixel coordinates we need to multiply the results by width and height of the image. First get the width and height of your image:

width, height = image.size

然后,从 boxes 对象中提取 ymin,xmin,ymax,xmax 并乘以得到 (x,y) 坐标:

Then, extract ymin,xmin,ymax,xmax from the boxes object and multiply to get the (x,y) coordinates:

ymin = boxes[0][i][0]*height
xmin = boxes[0][i][1]*width
ymax = boxes[0][i][2]*height
xmax = boxes[0][i][3]*width

最后打印框角坐标:

print 'Top left'
print (xmin,ymin,)
print 'Bottom right'
print (xmax,ymax)

这篇关于返回边界框的坐标谷歌的对象检测 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆