2017-11-17 109 views
0

如何繪製邊界框而不使用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 
+0

檢查盒子變暗的變量。在索引0處是圖像1的bboxes。在索引1是第二個圖像的Bbox的Nx4矩陣,等等...... –

回答

0

如果你看一下研究/ 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

非常感謝,它的工作原理! –

相關問題