使用 OpenCV 进行对象检测 API 但颜色输出错误

Object Detection API using OpenCV but got wrong color output

我尝试在 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()

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