从Tensorflow对象检测模型获取边界框

时间:2019-05-30 06:15:46

标签: python tensorflow computer-vision object-detection object-detection-api

我正在使用以下代码来获取图像中对象的边界框位置。

    image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
    image_np = load_image_into_numpy_array(image)  
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
    image_np_expanded = np.expand_dims(image_np, axis=0)
  # Actual detection.
    output_dict = run_inference_for_single_image(image_np, detection_graph)
  # Visualization of the results of a detection.
    vis_util.visualize_boxes_and_labels_on_image_array(    
        image_np,
        output_dict['detection_boxes'],
        output_dict['detection_classes'],
        output_dict['detection_scores'],
        category_index,
        instance_masks=output_dict.get('detection_masks'),
        use_normalized_coordinates=True,
        line_thickness=2)
    plt.figure(figsize=IMAGE_SIZE)
    plt.imshow(image_np)

    width = 1024
    height = 600

    for i,j in zip(output_dict['detection_boxes'],output_dict['detection_scores']):
        if(j>0.5):
            print(i[0]*width,i[2]*height,i[1]*width,i[3]*height)

测试图像的大小为(1024,600)。上面的代码输出以下内容

456.1627197265625 433.97676944732666 659.828125 562.1794939041138
430.4501953125 364.17006254196167 612.30224609375 440.01832008361816
453.7798156738281 326.9976854324341 584.5558471679688 374.18121099472046

我认为是x_min,y_min,x_max,y_max的顺序 请让我知道这是否是预期/期望的输出,如果不是,我该如何修改我的代码?

0 个答案:

没有答案