【问题标题】:Object Detection API using OpenCV but got wrong color output使用 OpenCV 的对象检测 API 但颜色输出错误
【发布时间】:2018-06-16 10:42:43
【问题描述】:

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

我更改了最后两个脚本:

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()

【问题讨论】:

  • 在显示前转换为 RGB。在显示之前使用cv2.cvtColor(image, cv2.COLOR_BGR2RGB)。 `
  • 你可以在显示之前使用 numpy 索引:img = img[..., ::-1]
  • 谢谢你的回答^^。通过更改此代码,我得到了正确的颜色。改变-----> cv2.imshow('image', image_np) ----- 到-----> cv2.imshow('image', cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB))跨度>

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-04-22
    • 2021-08-29
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多