| 57 | |
| 58 | |
| 59 | def pre_process_depth(input_video, apply_depth_detect: bool = True): |
| 60 | detected_maps = [] |
| 61 | for frame in input_video: |
| 62 | img = rearrange(frame, 'c h w -> h w c').cpu().numpy().astype(np.uint8) |
| 63 | img = HWC3(img) |
| 64 | if apply_depth_detect: |
| 65 | detected_map, _ = apply_midas(img) |
| 66 | else: |
| 67 | detected_map = img |
| 68 | detected_map = HWC3(detected_map) |
| 69 | H, W, C = img.shape |
| 70 | detected_map = cv2.resize(detected_map, (W, H), interpolation=cv2.INTER_NEAREST) |
| 71 | detected_maps.append(detected_map[None]) |
| 72 | detected_maps = np.concatenate(detected_maps) |
| 73 | control = torch.from_numpy(detected_maps.copy()).float() / 255.0 |
| 74 | return rearrange(control, 'f h w c -> f c h w') |
| 75 | |
| 76 | |
| 77 | def pre_process_pose(input_video, apply_pose_detect: bool = True): |