【发布时间】:2018-06-16 10:42:43
【问题描述】:
我尝试在 tensorflow 对象检测 api 中检测图像。
但是matplotlib无法显示图像,所以我改用opencv显示图像结果。
我得到了结果,但图像颜色不正确: https://i.stack.imgur.com/OYQlA.jpg
我是否缺少任何颜色句柄脚本?
我更改了最后两个脚本:
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