如何绘制边界框而不使用张量流对象检测api中的归一化坐标
问题描述:
如何绘制边界框而不使用tensorflow object-detection api中的归一化坐标?在object_detection_tutorial.ipynb中,我注意到默认坐标是在标准化坐标中,框的形式是[xmin,ymin,xmax,ymax]以及如何将它们转换为[image_length xmin,image_width ymin,image_length xmax,image_width ymax ]? 我尝试使用如何绘制边界框而不使用张量流对象检测api中的归一化坐标
boxes[0]=boxes[0]*200
boxes[1]=boxes[1]*100
boxes[2]=boxes[2]*200
boxes[3]=boxes[3]*100
但发生错误:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-72-efcec9615ee3> in <module>()
30 feed_dict={image_tensor: image_np_expanded})
31 boxes[0]=boxes[0]*200
---> 32 boxes[1]=boxes[1]*100
33 boxes[2]=boxes[2]*200
34 boxes[3]=boxes[3]*100
IndexError: index 1 is out of bounds for axis 0 with size 1
答
如果你看一下研究/ object_detection/utils的/ visualization_utils.py框[0] YMIN不是当你乘这些坐标XMIN与100或200确保它仍然在图像边界(im_width,im_height)。
您可以尝试框[0] * 100,框[1] * -200,框[2] * -100,框[3] * 200,这与此代码类似。
ymin = boxes[0]*100
xmin = boxes[1]*-200
ymax = boxes[2]*-100
xmax = boxes[3]*200
draw = ImageDraw.Draw(image)
im_width, im_height = image.size
(left, right, top, bottom) = (xmin * im_width, xmax * im_width,
ymin * im_height, ymax * im_height)
draw.line([(left, top), (left, bottom), (right, bottom),
(right, top), (left, top)], width=thickness, fill=color)
+0
非常感谢,它的工作原理! –
检查盒子变暗的变量。在索引0处是图像1的bboxes。在索引1是第二个图像的Bbox的Nx4矩阵,等等...... –