如何绘制边界框而不使用tensorflow object-detection api中的标准化坐标?在object_detection_tutorial.ipynb中,我注意到默认坐标是标准化坐标,框的形式是[xmin,ymin,xmax,ymax]以及如何将它们转换为[image_length xmin,image_width ymin,image_length < EM> XMAX,IMAGE_WIDTH YMAX]? 我尝试使用
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
答案 0 :(得分:0)
如果你看一下research / object_detection / utils / visualization_utils.py,当你将这些坐标乘以100或200时,方框[0]是ymin而不是xmin,确保它仍然在图像边界(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)