MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / get_crop_info

Function get_crop_info

detrsmpl/models/utils/SMPLX.py:137–183  ·  view source on GitHub ↗

Get the transformation of points on the cropped image to the points on the original image.

(points,
                  img_metas,
                  scale_factor: float = 1.0,
                  crop_size: int = 256)

Source from the content-addressed store, hash-verified

135
136
137def get_crop_info(points,
138 img_metas,
139 scale_factor: float = 1.0,
140 crop_size: int = 256):
141 """Get the transformation of points on the cropped image to the points on
142 the original image."""
143 device = points.device
144 dtype = points.dtype
145 batch_size = points.shape[0]
146 # Get the image to crop transformations and bounding box sizes
147 crop_transforms = []
148 img_bbox_sizes = []
149 for img_meta in img_metas:
150 crop_transforms.append(img_meta['crop_transform'])
151 img_bbox_sizes.append(img_meta['scale'].max())
152
153 img_bbox_sizes = torch.tensor(img_bbox_sizes, dtype=dtype, device=device)
154
155 crop_transforms = torch.tensor(crop_transforms, dtype=dtype, device=device)
156
157 crop_transforms = torch.cat([
158 crop_transforms,
159 torch.tensor([0.0, 0.0, 1.0], dtype=dtype, device=device).expand(
160 [batch_size, 1, 3])
161 ],
162 dim=1)
163
164 inv_crop_transforms = torch.inverse(crop_transforms)
165
166 # center on the cropped body image
167 center_body_crop, bbox_size = points_to_bbox(
168 points, bbox_scale_factor=scale_factor)
169
170 orig_bbox_size = bbox_size / crop_size * img_bbox_sizes
171
172 # Compute the center of the crop in the original image
173 center = (torch.einsum(
174 'bij,bj->bi', [inv_crop_transforms[:, :2, :2], center_body_crop]) +
175 inv_crop_transforms[:, :2, 2])
176
177 return {
178 'center': center.reshape(-1, 2),
179 'orig_bbox_size': orig_bbox_size,
180 # 'bbox_size': bbox_size.reshape(-1),
181 'inv_crop_transforms': inv_crop_transforms,
182 # 'center_body_crop': 2 * center_body_crop / (crop_size-1) - 1,
183 }
184
185
186def concat_images(images: List[torch.Tensor]):

Callers 2

__call__Method · 0.85
__call__Method · 0.85

Calls 2

points_to_bboxFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected