Files
posefit-server/app/vision/frame_utils.py
T

27 lines
712 B
Python

from __future__ import annotations
import cv2
import numpy as np
TARGET_WIDTH = 1280
TARGET_HEIGHT = 720
def resize_to_target(image: np.ndarray, width: int = TARGET_WIDTH, height: int = TARGET_HEIGHT) -> np.ndarray:
"""将图像缩放到目标尺寸(仅当尺寸不一致时)"""
h, w = image.shape[:2]
if w == width and h == height:
return image
return cv2.resize(image, (width, height))
def bgr_to_rgba(bgr: np.ndarray) -> np.ndarray:
"""将BGR格式图像转换为RGBA格式"""
return cv2.cvtColor(bgr, cv2.COLOR_BGR2RGBA)
def bgr_to_rgb(bgr: np.ndarray) -> np.ndarray:
"""将BGR格式图像转换为RGB格式"""
return cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)