使用OpenCV的对象检测API,但颜色输出错误
我尝试在tensorflow对象检测api中检测图像 但matplotlib无法成功显示图像,因此我改为使用opencv显示图像结果 我得到了结果,但图像颜色不正确: 我是否缺少任何颜色句柄脚本 原始资料来源: 我更改了最后2个脚本:使用OpenCV的对象检测API,但颜色输出错误,opencv,tensorflow,object-detection,object-detection-api,Opencv,Tensorflow,Object Detection,Object Detection Api,我尝试在tensorflow对象检测api中检测图像 但matplotlib无法成功显示图像,因此我改为使用opencv显示图像结果 我得到了结果,但图像颜色不正确: 我是否缺少任何颜色句柄脚本 原始资料来源: 我更改了最后2个脚本: for image_path in TEST_IMAGE_PATHS: image = Image.open(image_path) image_np = load_image_into_numpy_array(image) image
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.cvt颜色(图像,cv2.COLOR\u BGR2RGB)
在显示前转换为RGB。在显示之前使用cv2.cvt颜色(图像,cv2.COLOR\u BGR2RGB)
`在显示之前,您可以使用numpy索引:img=img[…,::-1]
。谢谢您的回答。通过更改此代码,我得到了正确的颜色。将------>cv2.imshow('image',image\u np)-----更改为------>cv2.imshow('image',cv2.cvt颜色(image\u np,cv2.COLOR\u BGR2RGB))