-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (54 loc) · 1.97 KB
/
test.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# import cv2
# import numpy as np
# from PIL import Image
# img = cv2.imread('/data/PhenoBench/val/annotations/05-15_00053_P0030943_plant_1889.png', cv2.CV_16UC1)
# img_array = np.array(img)
# print(np.unique(img_array))
# img = Image.open('/data/PhenoBench/val/annotations/05-15_00053_P0030943_plant_1889.png')
# img_array = np.array(img)
# print(np.unique(img_array))
import json
import os
import cv2
ROOT_DIR = '/data/PhenoBench/val'
with open('/data/PhenoBench/plant_instances_train.json') as f:
info = json.load(f)
# for img_anno in info['annotations']:
# img_anno['iscrowd'] = 0
# with open('{}/leaf_0.json'.format(ROOT_DIR), 'w') as output_json_file:
# json.dump(info, output_json_file)
# print('write ok!')
num_list = []
print(info.keys())
for anno in info['annotations']:
polygon = anno['segmentation']
polygon_len = len(polygon)
num_list.append(polygon_len)
print(set(num_list))
print(info['categories'])
print(info['annotations'][0])
# print(info['annotations'][133]['segmentation'])
# print(info['images'][133]['file_name'])
print(info['images'][0])
# print(info['categories'])
# img_path = os.path.join('/data/PhenoBench/val/images/', info['images'][0]['file_name'])
# bbox = info['annotations'][2]['bbox']
# img = cv2.imread(img_path)
# cv2.rectangle(img, (int(bbox[0]), int(bbox[1])), (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3])), (0, 0, 255), 2)
# cv2.imwrite('test.png', img)
# with open('/data/PhenoBench/val/plant.json') as f:
# info = json.load(f)
# # for img_anno in info['annotations']:
# # img_anno['iscrowd'] = 0
# # with open('{}/leaf_0.json'.format(ROOT_DIR), 'w') as output_json_file:
# # json.dump(info, output_json_file)
# # print('write ok!')
# num_list = []
# print(info.keys())
# for anno in info['annotations']:
# polygon = anno['segmentation']
# polygon_len = len(polygon)
# num_list.append(polygon_len)
# print(set(num_list))
# # print(info['annotations'][133]['segmentation'])
# print(info['images'][133]['file_name'])