Skip to content

Commit

Permalink
fix show_image to return BGR output (#390)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Davidyuk <igor.davidyuk@intel.com>
  • Loading branch information
igor-davidyuk authored Apr 17, 2024
1 parent 2abfaf5 commit fb10784
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 4 additions & 5 deletions geti_sdk/prediction_visualization/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,21 @@ def draw(
Must be in range [0, 1].
:return: Output image with annotations in RGB format
"""
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

if confidence_threshold is not None:
annotation = annotation.filter_by_confidence(confidence_threshold)
result = self.shape_drawer.draw(
image, annotation, labels=[], fill_shapes=fill_shapes
)
return cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
return result

def show(self, image: np.ndarray) -> None:
"""
Show result image.
:param image: Image to be shown.
:param image: Image to be shown (in RGB order).
"""
cv2.imshow(self.window_name, image)
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
cv2.imshow(self.window_name, image_bgr)

def is_quit(self) -> bool:
"""Check user wish to quit."""
Expand Down
8 changes: 6 additions & 2 deletions geti_sdk/utils/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def show_image_with_annotation_scene(
image=rgb_image, annotation=annotation_scene, fill_shapes=fill_shapes
)

# For compatibility with the previous version of the function
# return image in BGR order; to be changed in 2.0.
result_bgr = cv2.cvtColor(result, cv2.COLOR_RGB2BGR)

if filepath is None:
if show_results:
image = PILImage.fromarray(result)
Expand All @@ -110,13 +114,13 @@ def show_image_with_annotation_scene(
else:
display(image)
else:
success, buffer = cv2.imencode(".jpg", result)
success, buffer = cv2.imencode(".jpg", result_bgr)
if success:
buffer.tofile(filepath)
else:
raise RuntimeError("Unable to encode output image to .jpg format.")

return result
return result_bgr


def show_video_frames_with_annotation_scenes(
Expand Down

0 comments on commit fb10784

Please sign in to comment.