6e1a22ba8b
assets/conveyors (274 МБ) - ленты и угловая секция NVIDIA, на которые ссылается сцена относительным путём. Раньше исключались как перекачиваемые, но без них сцена не композится из коробки. cv/ - код стереодвижков, которые вызывает control_test, без весов: * defom-stereo - рабочий бейзлайн (DEFOM vitl, вход 480, iters 24) * crestereo - второй движок, точнее по габаритам (MAE 23.5 против 32.8 мм) * fast-foundationstereo - проверялся, в бейзлайн не вошёл * circular_section.py - показатель кругового сечения, перенесён в measure_plane.py: выравнивает облако по СОБСТВЕННЫМ главным осям и режет на пяти высотах вдоль каждой. Три самодельные версии (мировые оси, одно сечение) давали хуже; результаты проверки на эталонной геометрии - в circular_section_results.json Веса по-прежнему не в репозитории - источники в MODELS.md. Наборы кадров прежних прогонов (cv/flow_*, 1.26 ГБ) исключены: это выход, а не исходники. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
159 lines
5.9 KiB
Python
159 lines
5.9 KiB
Python
import numpy as np
|
|
import cv2
|
|
|
|
|
|
class Resize(object):
|
|
"""Resize sample to given size (width, height).
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
width,
|
|
height,
|
|
resize_target=True,
|
|
keep_aspect_ratio=False,
|
|
ensure_multiple_of=1,
|
|
resize_method="lower_bound",
|
|
image_interpolation_method=cv2.INTER_AREA,
|
|
):
|
|
"""Init.
|
|
|
|
Args:
|
|
width (int): desired output width
|
|
height (int): desired output height
|
|
resize_target (bool, optional):
|
|
True: Resize the full sample (image, mask, target).
|
|
False: Resize image only.
|
|
Defaults to True.
|
|
keep_aspect_ratio (bool, optional):
|
|
True: Keep the aspect ratio of the input sample.
|
|
Output sample might not have the given width and height, and
|
|
resize behaviour depends on the parameter 'resize_method'.
|
|
Defaults to False.
|
|
ensure_multiple_of (int, optional):
|
|
Output width and height is constrained to be multiple of this parameter.
|
|
Defaults to 1.
|
|
resize_method (str, optional):
|
|
"lower_bound": Output will be at least as large as the given size.
|
|
"upper_bound": Output will be at max as large as the given size. (Output size might be smaller than given size.)
|
|
"minimal": Scale as least as possible. (Output size might be smaller than given size.)
|
|
Defaults to "lower_bound".
|
|
"""
|
|
self.__width = width
|
|
self.__height = height
|
|
|
|
self.__resize_target = resize_target
|
|
self.__keep_aspect_ratio = keep_aspect_ratio
|
|
self.__multiple_of = ensure_multiple_of
|
|
self.__resize_method = resize_method
|
|
self.__image_interpolation_method = image_interpolation_method
|
|
|
|
def constrain_to_multiple_of(self, x, min_val=0, max_val=None):
|
|
y = (np.round(x / self.__multiple_of) * self.__multiple_of).astype(int)
|
|
|
|
if max_val is not None and y > max_val:
|
|
y = (np.floor(x / self.__multiple_of) * self.__multiple_of).astype(int)
|
|
|
|
if y < min_val:
|
|
y = (np.ceil(x / self.__multiple_of) * self.__multiple_of).astype(int)
|
|
|
|
return y
|
|
|
|
def get_size(self, width, height):
|
|
# determine new height and width
|
|
scale_height = self.__height / height
|
|
scale_width = self.__width / width
|
|
|
|
if self.__keep_aspect_ratio:
|
|
if self.__resize_method == "lower_bound":
|
|
# scale such that output size is lower bound
|
|
if scale_width > scale_height:
|
|
# fit width
|
|
scale_height = scale_width
|
|
else:
|
|
# fit height
|
|
scale_width = scale_height
|
|
elif self.__resize_method == "upper_bound":
|
|
# scale such that output size is upper bound
|
|
if scale_width < scale_height:
|
|
# fit width
|
|
scale_height = scale_width
|
|
else:
|
|
# fit height
|
|
scale_width = scale_height
|
|
elif self.__resize_method == "minimal":
|
|
# scale as least as possbile
|
|
if abs(1 - scale_width) < abs(1 - scale_height):
|
|
# fit width
|
|
scale_height = scale_width
|
|
else:
|
|
# fit height
|
|
scale_width = scale_height
|
|
else:
|
|
raise ValueError(f"resize_method {self.__resize_method} not implemented")
|
|
|
|
if self.__resize_method == "lower_bound":
|
|
new_height = self.constrain_to_multiple_of(scale_height * height, min_val=self.__height)
|
|
new_width = self.constrain_to_multiple_of(scale_width * width, min_val=self.__width)
|
|
elif self.__resize_method == "upper_bound":
|
|
new_height = self.constrain_to_multiple_of(scale_height * height, max_val=self.__height)
|
|
new_width = self.constrain_to_multiple_of(scale_width * width, max_val=self.__width)
|
|
elif self.__resize_method == "minimal":
|
|
new_height = self.constrain_to_multiple_of(scale_height * height)
|
|
new_width = self.constrain_to_multiple_of(scale_width * width)
|
|
else:
|
|
raise ValueError(f"resize_method {self.__resize_method} not implemented")
|
|
|
|
return (new_width, new_height)
|
|
|
|
def __call__(self, sample):
|
|
width, height = self.get_size(sample["image"].shape[1], sample["image"].shape[0])
|
|
|
|
# resize sample
|
|
sample["image"] = cv2.resize(sample["image"], (width, height), interpolation=self.__image_interpolation_method)
|
|
|
|
if self.__resize_target:
|
|
if "depth" in sample:
|
|
sample["depth"] = cv2.resize(sample["depth"], (width, height), interpolation=cv2.INTER_NEAREST)
|
|
|
|
if "mask" in sample:
|
|
sample["mask"] = cv2.resize(sample["mask"].astype(np.float32), (width, height), interpolation=cv2.INTER_NEAREST)
|
|
|
|
return sample
|
|
|
|
|
|
class NormalizeImage(object):
|
|
"""Normlize image by given mean and std.
|
|
"""
|
|
|
|
def __init__(self, mean, std):
|
|
self.__mean = mean
|
|
self.__std = std
|
|
|
|
def __call__(self, sample):
|
|
sample["image"] = (sample["image"] - self.__mean) / self.__std
|
|
|
|
return sample
|
|
|
|
|
|
class PrepareForNet(object):
|
|
"""Prepare sample for usage as network input.
|
|
"""
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def __call__(self, sample):
|
|
image = np.transpose(sample["image"], (2, 0, 1))
|
|
sample["image"] = np.ascontiguousarray(image).astype(np.float32)
|
|
|
|
if "depth" in sample:
|
|
depth = sample["depth"].astype(np.float32)
|
|
sample["depth"] = np.ascontiguousarray(depth)
|
|
|
|
if "mask" in sample:
|
|
sample["mask"] = sample["mask"].astype(np.float32)
|
|
sample["mask"] = np.ascontiguousarray(sample["mask"])
|
|
|
|
return sample
|