ref: create vision_chunk

This commit is contained in:
2025-12-21 20:13:51 +03:00
parent 92b6b0b0fe
commit 9d4839aa2a
6 changed files with 221 additions and 152 deletions

15
utility.py Normal file
View File

@@ -0,0 +1,15 @@
from PIL import Image
import cv2
import numpy as np
def cv2_to_pil(cv_image: np.ndarray) -> Image.Image:
"""
cv2.MatLike (BGR/RGB/Grayscale) → PIL.Image
"""
if len(cv_image.shape) == 3 and cv_image.shape[2] == 3:
cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
return Image.fromarray(cv_image)
def image_to_numpy(self, image: Image.Image) -> np.ndarray:
"""Конвертирует PIL Image в numpy array для OpenCV"""
return np.array(image)