MCPcopy Create free account
hub / github.com/ARM-software/AVH / __cropFrame

Method __cropFrame

interface/vstream/python/vsi_video_server.py:386–419  ·  view source on GitHub ↗

Crop the input frame to match the specified aspect ratio. Args: frame: The input frame (as NumPy array) to be cropped. aspect_ratio: The target aspect ratio (width/height). Returns: frame: The cropped frame.

(self, frame, target_aspect_ratio)

Source from the content-addressed store, hash-verified

384 logger.info("_disableStream: stream disabled")
385
386 def __cropFrame(self, frame, target_aspect_ratio):
387 """
388 Crop the input frame to match the specified aspect ratio.
389
390 Args:
391 frame: The input frame (as NumPy array) to be cropped.
392 aspect_ratio: The target aspect ratio (width/height).
393 Returns:
394 frame: The cropped frame.
395 """
396 logger.debug(f"__cropFrame: original_size=({frame.shape[1]}, {frame.shape[0]}), target_aspect_ratio={target_aspect_ratio}")
397
398 # NumPY array shape is (height, width, channels)
399 frame_h = frame.shape[0]
400 frame_w = frame.shape[1]
401
402 frame_aspect_ratio = frame_w / frame_h
403
404 if frame_aspect_ratio > target_aspect_ratio:
405 # Frame is wider than target -> crop left and right
406 new_w = int(frame_h * target_aspect_ratio)
407 left = (frame_w - new_w) // 2
408 right = left + new_w
409 cropped = frame[:, left:right]
410 else:
411 # Frame is taller than target -> crop top and bottom
412 new_h = int(frame_w / target_aspect_ratio)
413 top = (frame_h - new_h) // 2
414 bottom = top + new_h
415 cropped = frame[top:bottom, :]
416
417 logger.debug(f"__cropFrame: cropped_size=({cropped.shape[1]}, {cropped.shape[0]})")
418
419 return cropped
420
421 def __resizeFrame(self, frame, target_width, target_height):
422 """

Callers 1

_readFrameMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected