Spaces:
Runtime error
Runtime error
File size: 988 Bytes
554b11d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import numpy as np
import cv2
def pil2cv(image):
''' PIL型 -> OpenCV型 '''
new_image = np.array(image, dtype=np.uint8)
if new_image.ndim == 2: # モノクロ
pass
elif new_image.shape[2] == 3: # カラー
new_image = cv2.cvtColor(new_image, cv2.COLOR_RGB2BGR)
elif new_image.shape[2] == 4: # 透過
new_image = cv2.cvtColor(new_image, cv2.COLOR_RGBA2BGRA)
return new_image
def candidate_to_json_string(arr):
a = [f'[{x:.2f}, {y:.2f}]' for x, y, *_ in arr]
return '[' + ', '.join(a) + ']'
# make subset to json
def subset_to_json_string(arr):
arr_str = ','.join(['[' + ','.join([f'{num:.2f}' for num in row]) + ']' for row in arr])
return '[' + arr_str + ']'
keypoint_index_mapping = [
0,
17,
6,
8,
10,
5,
7,
9,
12,
14,
16,
11,
13,
15,
2,
1,
4,
3,
]
def convert_keypoints(keypoints):
return [keypoints[i] for i in keypoint_index_mapping]
|