@@ -1123,6 +1123,7 @@ def load_file(self, file_path=None):
11231123 u"<p>Make sure <i>%s</i> is a valid label file." )
11241124 % (e , unicode_file_path ))
11251125 self .status ("Error reading %s" % unicode_file_path )
1126+
11261127 return False
11271128 self .image_data = self .label_file .image_data
11281129 self .line_color = QColor (* self .label_file .lineColor )
@@ -1156,7 +1157,7 @@ def load_file(self, file_path=None):
11561157 self .paint_canvas ()
11571158 self .add_recent_file (self .file_path )
11581159 self .toggle_actions (True )
1159- self .show_bounding_box_from_annotation_file (file_path )
1160+ self .show_bounding_box_from_annotation_file (self . file_path )
11601161
11611162 counter = self .counter_str ()
11621163 self .setWindowTitle (__appname__ + ' ' + file_path + ' ' + counter )
@@ -1196,10 +1197,15 @@ def show_bounding_box_from_annotation_file(self, file_path):
11961197 else :
11971198 xml_path = os .path .splitext (file_path )[0 ] + XML_EXT
11981199 txt_path = os .path .splitext (file_path )[0 ] + TXT_EXT
1200+ json_path = os .path .splitext (file_path )[0 ] + JSON_EXT
1201+
11991202 if os .path .isfile (xml_path ):
12001203 self .load_pascal_xml_by_filename (xml_path )
12011204 elif os .path .isfile (txt_path ):
12021205 self .load_yolo_txt_by_filename (txt_path )
1206+ elif os .path .isfile (json_path ):
1207+ self .load_create_ml_json_by_filename (json_path , file_path )
1208+
12031209
12041210 def resizeEvent (self , event ):
12051211 if self .canvas and not self .image .isNull ()\
@@ -1300,10 +1306,13 @@ def change_save_dir_dialog(self, _value=False):
13001306 if dir_path is not None and len (dir_path ) > 1 :
13011307 self .default_save_dir = dir_path
13021308
1309+ self .show_bounding_box_from_annotation_file (self .file_path )
1310+
13031311 self .statusBar ().showMessage ('%s . Annotation will be saved to %s' %
13041312 ('Change saved folder' , self .default_save_dir ))
13051313 self .statusBar ().show ()
13061314
1315+
13071316 def open_annotation_dialog (self , _value = False ):
13081317 if self .file_path is None :
13091318 self .statusBar ().showMessage ('Please select image first' )
@@ -1320,6 +1329,17 @@ def open_annotation_dialog(self, _value=False):
13201329 filename = filename [0 ]
13211330 self .load_pascal_xml_by_filename (filename )
13221331
1332+ elif self .label_file_format == LabelFileFormat .CREATE_ML :
1333+
1334+ filters = "Open Annotation JSON file (%s)" % ' ' .join (['*.json' ])
1335+ filename = ustr (QFileDialog .getOpenFileName (self , '%s - Choose a json file' % __appname__ , path , filters ))
1336+ if filename :
1337+ if isinstance (filename , (tuple , list )):
1338+ filename = filename [0 ]
1339+
1340+ self .load_create_ml_json_by_filename (filename , self .file_path )
1341+
1342+
13231343 def open_dir_dialog (self , _value = False , dir_path = None , silent = False ):
13241344 if not self .may_continue ():
13251345 return
@@ -1337,6 +1357,9 @@ def open_dir_dialog(self, _value=False, dir_path=None, silent=False):
13371357 target_dir_path = ustr (default_open_dir_path )
13381358 self .last_open_dir = target_dir_path
13391359 self .import_dir_images (target_dir_path )
1360+ self .default_save_dir = target_dir_path
1361+ if self .file_path :
1362+ self .show_bounding_box_from_annotation_file (file_path = self .file_path )
13401363
13411364 def import_dir_images (self , dir_path ):
13421365 if not self .may_continue () or not dir_path :
0 commit comments