使用OpenCV但是颜色输出错误的Object Detection API

时间:2018-06-16 10:42:44

标签: opencv tensorflow object-detection object-detection-api

我试图在tensorflow对象检测api中检测图像。

但是matplotlib无法成功显示图像所以我改为使用opencv来显示图像结果。

我得到了我的结果,但图片颜色不正确: https://i.stack.imgur.com/OYQlA.jpg

我错过了任何颜色处理脚本吗?

原始资料来源: https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb

我更改了最后2个脚本:

for image_path in TEST_IMAGE_PATHS:
    image = Image.open(image_path)
    image_np = load_image_into_numpy_array(image)
    image_np_expanded = np.expand_dims(image_np, axis=0)
    output_dict = run_inference_for_single_image(image_np, detection_graph)
    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=8)
    # plt.figure(figsize=IMAGE_SIZE)
    # plt.imshow(image_np)

    cv2.imshow('image', image_np)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:0)

Opencv使用BGR和Matplotlib RGB。你必须:     cv2.cvtColor(image, cv2.COLOR_BGR2RGB)