| 75 | |
| 76 | |
| 77 | def pre_process_pose(input_video, apply_pose_detect: bool = True): |
| 78 | detected_maps = [] |
| 79 | for frame in input_video: |
| 80 | img = rearrange(frame, 'c h w -> h w c').cpu().numpy().astype(np.uint8) |
| 81 | img = HWC3(img) |
| 82 | if apply_pose_detect: |
| 83 | detected_map, _ = apply_openpose(img) |
| 84 | else: |
| 85 | detected_map = img |
| 86 | detected_map = HWC3(detected_map) |
| 87 | H, W, C = img.shape |
| 88 | detected_map = cv2.resize(detected_map, (W, H), interpolation=cv2.INTER_NEAREST) |
| 89 | detected_maps.append(detected_map[None]) |
| 90 | detected_maps = np.concatenate(detected_maps) |
| 91 | control = torch.from_numpy(detected_maps.copy()).float() / 255.0 |
| 92 | return rearrange(control, 'f h w c -> f c h w') |
| 93 | |
| 94 | |
| 95 | def create_video(frames, fps, rescale=False, path=None, watermark=None): |