是的,在教程中变量
output_dict
可以用来实现这一点。注意传递给函数的所有变量
vis_util.visualize_boxes_and_labels_on_image_array
,它们包含方框,分数等
首先,您需要获取图像形状,因为框坐标是标准化形式。
img_height, img_width, img_channel = image_np.shape
</code>
然后将所有框坐标转换为绝对格式
absolute_coord = []
THRESHOLD = 0.7 # adjust your threshold here
N = len(output_dict[‘detection_boxes’])
for i in range(N):
if output_dict[‘score’][i] < THRESHOLD:
continue
box = output_dict[‘detection_boxes’]
ymin, xmin, ymax, xmax = box
x_up = int(xminimg_width)
y_up = int(yminimg_height)
x_down = int(xmaximg_width)
y_down = int(ymaximg_height)
absolute_coord.append((x_up,y_up,x_down,y_down))
</code>
然后,您可以使用numpy切片来获取边界框内的图像区域
bounding_box_img = []
for c in absolute_coord:
bounding_box_img.append(image_np[c[1]:c[3], c[0]:c[2],:])
</code>
然后只需保存所有numpy数组
bounding_box_img
作为图像。保存时,您可能需要更改形状,因为img处于形状[img_height,img_width,img_channel]。如果您使用得分数组,您甚至可以过滤掉所有低置信度分数的检测。
PS:我可能搞砸了
img_height
和
img_width
但这些应该给你一个起点。