15 lines
491 B
Python
15 lines
491 B
Python
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) |