Skip to content

Commit

Permalink
Deprecate image_src parameter on Frame.to_numpy_array() (#201)
Browse files Browse the repository at this point in the history
* Deprecate image_src parameter on Frame.to_numpy_array()

* Format
  • Loading branch information
pappacena authored May 23, 2024
1 parent 6288a23 commit 67034b8
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions landingai/pipeline/frameset.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,27 @@ def crop_predictions(self) -> "FrameSet":
pred_frames.append(new_frame)
return FrameSet(frames=pred_frames)

def to_numpy_array(self, image_src: str = "") -> np.ndarray:
def to_numpy_array(
self,
image_src: str = "",
*,
include_predictions: bool = False,
) -> np.ndarray:
"""Return a numpy array using RGB channel ordering. If this array is passed to OpenCV, you will need to convert it to BGR
Parameters
----------
image_src : if empty the source image will be converted. Otherwise the image will be selected from `other_images`
image_src (deprecated): if empty the source image will be displayed. Otherwise the image will be selected from `other_images`
include_predictions: If the image has predictions, should it be overlaid on top of the image?
"""
if image_src:
warnings.warn(
"image_src keyword on Frame.to_numpy_array is deprecated. Use include_predictions instead."
)
if image_src == "overlay":
include_predictions = True
if include_predictions:
image_src = "overlay"
img = (
self.image
if image_src == "" or image_src not in self.other_images
Expand Down Expand Up @@ -650,8 +664,8 @@ def save_video(
warnings.warn(
"image_src keyword on FrameSet.save_video is deprecated. Use include_predictions instead."
)
if include_predictions:
image_src = "overlay"
if image_src == "overlay":
include_predictions = True

total_frames = len(self.frames)
if total_frames == 0:
Expand All @@ -670,7 +684,9 @@ def save_video(

writer = imageio.get_writer(video_file_path, fps=video_fps)
for fr in self.frames:
writer.append_data(fr.to_numpy_array(image_src))
writer.append_data(
fr.to_numpy_array(include_predictions=include_predictions)
)
writer.close()

# TODO: Future delete if we get out of OpenCV
Expand Down

0 comments on commit 67034b8

Please sign in to comment.