You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import cv2 as cv
import numpy as np
img_size = (1280, 720) # Размер изображения для нормализации.
def image_transform(image: np.ndarray) -> np.ndarray:
'''
Трансформирует изображение нужным образом.
@param image: Исходная матрица с представлением изображения.
'''
image = cv.resize(image, (img_size[0], img_size[1]))
return image[:, :, ::-1]
def get_image_file_as_array(image_name: str) -> np.ndarray:
'''
Получает изображение из файла и нормализует его.
@param image_name: Путь до изображения.
'''
image = cv.imread(image_name)
image: np.ndarray # приведение типов
image = image_transform(image)
return image
def get_image_buf_as_array(buf) -> np.ndarray:
'''
Получает изображение из буфера и нормализует его.
@param image_name: Путь до изображения.
'''
image = cv.imdecode(buf, cv.IMREAD_COLOR)
image: np.ndarray # приведение типов
image = image_transform(image)
return image