Код: Выделить всё
@dataclass
class Measurements:
width: int
height: int
head_left: int
head_right: int
head_width: int
head_top: int
head_bottom: int
head_height: int
space_above_head: int
space_below_chin: int
eyes_to_bottom_edge: int
eyes_to_top_edge: int
@dataclass
class Constraints:
width: Bounds = (None, None)
height: Bounds = (None, None)
head_left: Bounds = (None, None)
head_right: Bounds = (None, None)
head_width: Bounds = (None, None)
head_top: Bounds = (None, None)
head_bottom: Bounds = (None, None)
head_height: Bounds = (None, None)
space_above_head: Bounds = (None, None)
space_below_chin: Bounds = (None, None)
eyes_to_bottom_edge: Bounds = (None, None)
eyes_to_top_edge: Bounds = (None, None)
Я пробовал
Код: Выделить всё
Constraints = dataclasses.make_dataclass('Constraints', [(f.name, Bounds, dataclasses.field(default=(None, None))) for f in dataclasses.fields(Measurements)])
Код: Выделить всё
def crop(image: npt.NDArray, constraints: Constraints) -> npt.NDArray:
^
Может ли кто-нибудь придумать лучшее решение ?
Подробнее здесь: https://stackoverflow.com/questions/793 ... mmatically
Мобильная версия