From 12f2fae4dd1e6b66e034802cb6017b49bfa2d147 Mon Sep 17 00:00:00 2001 From: mh iyer <58288779+mhiyer@users.noreply.github.com> Date: Thu, 20 Jan 2022 19:57:26 +0800 Subject: [PATCH] Update visualize_single_image.py The code uses BGR images (opencv reads images as BGR by default). Since training uses RGB images, inference should use RGB images as well. --- visualize_single_image.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/visualize_single_image.py b/visualize_single_image.py index fdc47b8fd..b6122e9b7 100644 --- a/visualize_single_image.py +++ b/visualize_single_image.py @@ -52,6 +52,9 @@ def detect_image(image_path, model_path, class_list): for img_name in os.listdir(image_path): image = cv2.imread(os.path.join(image_path, img_name)) + + # Opencv reads images as BGR format by default. This needs to be changed to RGB, since training uses RGB, not BGR images. + image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB) if image is None: continue image_orig = image.copy() @@ -114,8 +117,9 @@ def detect_image(image_path, model_path, class_list): # draw_caption(img, (x1, y1, x2, y2), label_name) draw_caption(image_orig, (x1, y1, x2, y2), caption) cv2.rectangle(image_orig, (x1, y1), (x2, y2), color=(0, 0, 255), thickness=2) - - cv2.imshow('detections', image_orig) + + # change from RGB-> BGR for visualization + cv2.imshow('detections', cv2.cvtColor(image_orig, cv2.COLOR_RGB2BGR)) cv2.waitKey(0)