MCPcopy Create free account
hub / github.com/MAC-VO/MAC-VO / ScaleFrame

Class ScaleFrame

DataLoader/Transform.py:41–94  ·  view source on GitHub ↗

Scale the image & ground truths on u and v direction and modify the camera intrinsic accordingly.

Source from the content-addressed store, hash-verified

39
40
41class ScaleFrame(IDataTransform[StereoFrame, StereoFrame]):
42 """
43 Scale the image & ground truths on u and v direction and modify the camera intrinsic accordingly.
44 """
45 @classmethod
46 def is_valid_config(cls, config: SimpleNamespace | None) -> None:
47 cls._enforce_config_spec(config, {
48 "scale_u": lambda v: isinstance(v, (float, int)) and v > 0,
49 "scale_v": lambda v: isinstance(v, (float, int)) and v > 0,
50 "interp" : lambda v: v in {"nearest", "bilinear"}
51 })
52
53 @staticmethod
54 def scale_stereo(data: StereoData, scale_u: float, scale_v: float, interpolate: Literal["nearest", "bilinear"]) -> StereoData:
55 match interpolate:
56 case "bilinear": interp = InterpolationMode.BILINEAR
57 case "nearest" : interp = InterpolationMode.NEAREST_EXACT
58
59 raw_height = data.height
60 raw_width = data.width
61
62 target_h = int(raw_height / scale_v)
63 target_w = int(raw_width / scale_u)
64
65 round_scale_v = raw_height / target_h
66 round_scale_u = raw_width / target_w
67
68 data.K = data.K.clone()
69 data.height = target_h
70 data.width = target_w
71 data.K[:, 0] /= round_scale_u
72 data.K[:, 1] /= round_scale_v
73
74 data.imageL = resize(data.imageL, [target_h, target_w], interpolation=interp)
75 data.imageR = resize(data.imageR, [target_h, target_w], interpolation=interp)
76
77 if data.gt_flow is not None:
78 data.gt_flow = resize(data.gt_flow, [target_h, target_w], interpolation=interp)
79 data.gt_flow[:, 0] /= round_scale_u
80 data.gt_flow[:, 1] /= round_scale_v
81
82 if data.flow_mask is not None:
83 data.flow_mask = resize(data.flow_mask, [target_h, target_w], interpolation=interp)
84
85 if data.gt_depth is not None:
86 data.gt_depth = resize(data.gt_depth, [target_h, target_w], interpolation=interp)
87
88 return data
89
90 def forward(self, frame: StereoFrame) -> StereoFrame:
91 frame.stereo = self.scale_stereo(
92 frame.stereo, scale_u=self.config.scale_u, scale_v=self.config.scale_v, interpolate=self.config.interp
93 )
94 return frame
95
96
97class CenterCropFrame(IDataTransform[StereoFrame, StereoFrame]):

Callers 3

EvalDepth.pyFile · 0.90
EvalFlow.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected