MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / preprocess

Method preprocess

tools/preprocess/pose2d.py:315–334  ·  view source on GitHub ↗
(img, bbox=None, input_resolution=(256, 192), rescale=1.25, mask=None, **kwargs)

Source from the content-addressed store, hash-verified

313
314 @staticmethod
315 def preprocess(img, bbox=None, input_resolution=(256, 192), rescale=1.25, mask=None, **kwargs):
316 if bbox is None or bbox[-1] <= 0 or (bbox[2] - bbox[0]) < 10 or (bbox[3] - bbox[1]) < 10:
317 bbox = np.array([0, 0, img.shape[1], img.shape[0]])
318
319 bbox_xywh = bbox
320 if mask is not None:
321 img = np.where(mask > 128, img, mask)
322
323 if isinstance(input_resolution, int):
324 center, scale = bbox_from_detector(bbox_xywh, (input_resolution, input_resolution), rescale=rescale)
325 img, new_shape, old_xy, new_xy = crop(img, center, scale, (input_resolution, input_resolution))
326 else:
327 center, scale = bbox_from_detector(bbox_xywh, input_resolution, rescale=rescale)
328 img, new_shape, old_xy, new_xy = crop(img, center, scale, (input_resolution[0], input_resolution[1]))
329
330 IMG_NORM_MEAN = np.array([0.485, 0.456, 0.406])
331 IMG_NORM_STD = np.array([0.229, 0.224, 0.225])
332 img_norm = (img / 255.0 - IMG_NORM_MEAN) / IMG_NORM_STD
333 img_norm = img_norm.transpose(2, 0, 1).astype(np.float32)
334 return img_norm, np.array(center), np.array(scale)
335
336
337class Pose2d:

Callers

nothing calls this directly

Calls 2

bbox_from_detectorFunction · 0.90
cropFunction · 0.90

Tested by

no test coverage detected