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

Method select_point

Module/KeypointSelector.py:169–205  ·  view source on GitHub ↗
(self, frame: StereoData, numPoint: int, depth0_est: IStereoDepth.Output, depth1_est: IStereoDepth.Output, match_est: IMatcher.Output | None)

Source from the content-addressed store, hash-verified

167 of keypoint candidates.
168 """
169 def select_point(self, frame: StereoData, numPoint: int, depth0_est: IStereoDepth.Output, depth1_est: IStereoDepth.Output, match_est: IMatcher.Output | None) -> torch.Tensor:
170 image = frame.imageL[0]
171
172 image_grad = torch.nn.functional.conv2d(
173 image.unsqueeze(0),
174 torch.tensor([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
175 .float()
176 .expand((1, 3, 3, 3)),
177 padding=1,
178 )[0].abs()
179 image_grad_avg = image_grad.mean(dim=(1, 2), keepdim=True)
180 image_grad_std = image_grad.std(dim=(1, 2), keepdim=True)
181 # Positions with sufficient gradient (feature) > +3std
182 points = image_grad > (image_grad_avg + self.config.grad_std * image_grad_std)
183
184 # Positions that are not too close to the edge of image
185 border_mask = torch.zeros_like(points)
186 border_mask[
187 ..., self.config.mask_width : -self.config.mask_width, self.config.mask_width : -self.config.mask_width
188 ] = 1.0
189 points = points * border_mask
190
191 # Positions that are sufficiently far away (sparse)
192 image_grad_erode = torch.nn.functional.max_pool2d(
193 image_grad,
194 kernel_size=self.config.nms_size,
195 stride=1,
196 padding=(self.config.nms_size // 2),
197 )
198 image_grad_nms = image_grad == image_grad_erode
199 points = points * image_grad_nms
200
201 selected_points = torch.nonzero(points, as_tuple=False)
202
203 # Randomly select points
204 perm = torch.randperm(selected_points.shape[0])[:numPoint]
205 return selected_points[perm][..., 1:].roll(shifts=1, dims=1)
206
207 @classmethod
208 def is_valid_config(cls, config: SimpleNamespace | None) -> None:

Callers

nothing calls this directly

Calls 2

tensorMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected