| 878 | self.sample_ratio = sample_ratio |
| 879 | |
| 880 | def __call__(self, results): |
| 881 | |
| 882 | |
| 883 | assert 'bbox_xywh' in results |
| 884 | bbox_xywh = results['bbox_xywh'].copy() |
| 885 | crop_person_number = len(bbox_xywh) |
| 886 | if random.random() < self.sample_ratio: |
| 887 | crop_person_number = np.random.randint(len(bbox_xywh)) + 1 |
| 888 | |
| 889 | sample_ids = np.array( |
| 890 | random.sample(list(range(len(bbox_xywh))), crop_person_number)) |
| 891 | |
| 892 | bbox_xyxy = xywh2xyxy(bbox_xywh)[sample_ids] |
| 893 | |
| 894 | leftTop_ = bbox_xyxy[:, :2] |
| 895 | leftTop_ = np.array([np.min(leftTop_[:, 0]), np.min(leftTop_[:, 1])]) |
| 896 | rightBottom_ = bbox_xyxy[:, 2:4] |
| 897 | rightBottom_ = np.array( |
| 898 | [np.max(rightBottom_[:, 0]), |
| 899 | np.max(rightBottom_[:, 1])]) |
| 900 | bbox_xyxy = np.concatenate([leftTop_, rightBottom_]) |
| 901 | results['bbox_xyxy'] = bbox_xyxy |
| 902 | center = (rightBottom_ + leftTop_) / 2 |
| 903 | scale = (rightBottom_ - leftTop_) |
| 904 | scale[0] = scale[1] = max(scale) |
| 905 | results['center'] = center |
| 906 | results['scale'] = scale |
| 907 | return results |
| 908 | |
| 909 | |
| 910 | |