SIA86 commited on
Commit
5871d59
·
1 Parent(s): 6618677

Upload WaterFlowCountersRecognition.py

Browse files
Files changed (1) hide show
  1. WaterFlowCountersRecognition.py +6 -6
WaterFlowCountersRecognition.py CHANGED
@@ -1,7 +1,6 @@
1
  import json
2
  import os
3
  import collections
4
- from PIL import Image
5
 
6
  import datasets
7
 
@@ -103,8 +102,9 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
103
  for indx, name in enumerate(_REGION_ROTETION):
104
  rotation_to_id[name] = indx
105
 
106
- with open('_annotations.json', 'r', encoding='utf-8') as fr:
107
- json_file = json.load(fr)
 
108
 
109
  for file in os.listdir(folder_dir):
110
  filepath = os.path.join(folder_dir, file)
@@ -116,9 +116,9 @@ class WaterFlowCounter(datasets.GeneratorBasedBuilder):
116
  all_y = []
117
  names = []
118
 
119
- for el in json_file['_via_img_metadata']:
120
- if json_file['_via_img_metadata'][el]['filename'] == file:
121
- for region in json_file['_via_img_metadata'][el]['regions']:
122
  all_x.append(region['shape_attributes']['all_points_x'])
123
  all_y.append(region['shape_attributes']['all_points_y'])
124
  names.append(name_to_id[list(region['region_attributes']['name'].keys())[0]])
 
1
  import json
2
  import os
3
  import collections
 
4
 
5
  import datasets
6
 
 
102
  for indx, name in enumerate(_REGION_ROTETION):
103
  rotation_to_id[name] = indx
104
 
105
+ annotation_filepath = os.path.join(folder_dir, _ANNOTATION_FILENAME)
106
+ with open(annotation_filepath, "r") as f:
107
+ annotations = json.load(f)
108
 
109
  for file in os.listdir(folder_dir):
110
  filepath = os.path.join(folder_dir, file)
 
116
  all_y = []
117
  names = []
118
 
119
+ for el in annotations['_via_img_metadata']:
120
+ if annotations['_via_img_metadata'][el]['filename'] == file:
121
+ for region in annotations['_via_img_metadata'][el]['regions']:
122
  all_x.append(region['shape_attributes']['all_points_x'])
123
  all_y.append(region['shape_attributes']['all_points_y'])
124
  names.append(name_to_id[list(region['region_attributes']['name'].keys())[0]])