@@ -262,6 +262,38 @@ def video_to_voc(self,save_path,detector=None,fps=5):
262262 index = index + 1
263263 processBar .update ()
264264
265+ def VOCDatasetToYoloDatasets (self ):
266+ VOC_LABELS = []
267+ with open (os .path .join (self .root_path ,"label_list.txt" ),"rb" ) as f :
268+ content_list = f .readlines ()
269+ for content in content_list :
270+ content = str (content , encoding = "utf-8" ).strip ()
271+ VOC_LABELS .append (content )
272+ progressBar = ProgressBar (len (os .listdir (self .root_path )))
273+ for year in os .listdir (self .root_path ):
274+ if os .path .isdir (os .path .join (self .root_path ,year )):
275+ labels_dir = os .path .join (self .root_path ,year ,"Labels" )
276+ if os .path .exists (labels_dir ):
277+ shutil .rmtree (labels_dir )
278+ CreateSavePath (labels_dir )
279+ xml_path_list = GetFilesWithLastNamePath (os .path .join (self .root_path ,year ,DIRECTORY_ANNOTATIONS ),".xml" )
280+ for xml_path in xml_path_list :
281+ imagename ,shape , bboxes , labels_text ,labels , difficult , truncated = ProcessXml (xml_path )
282+ with open (os .path .join (labels_dir ,"{}.txt" .format (imagename .split ("." )[0 ])),"wb" ) as f :
283+ for (label , box ) in zip (labels_text , bboxes ):
284+ f .write ("{} {} {} {} {}" .format (VOC_LABELS .index (label ),box [0 ],box [1 ],box [2 ],box [3 ]).encode ("utf-8" ))
285+ progressBar .update ()
286+ # with open(os.path.join(self.root_path, "train.txt"), "rb") as f:
287+ # content_list = f.readlines()
288+ # for content in content_list:
289+ # content = str(content, encoding="utf-8")
290+ # image_path, xml_path = os.path.join(self.root_path, content.split(" ")[0].strip()), os.path.join(self.root_path, content.split(" ")[1].strip())
291+ # imagename,shape, bboxes, labels_text,labels, difficult, truncated = ProcessXml(xml_path)
292+ # for (label,box) in zip(labels_text,bboxes):
293+ # print(VOC_LABELS.index(label),box)
294+
295+
296+
265297def remove_voc_imagesets (root_path ):
266298 processBar = ProgressBar (len (os .listdir (root_path )))
267299 for year in os .listdir (root_path ):
@@ -287,7 +319,9 @@ def paddle_pretrain_detection_dataset(root_path,detector,threshold=0.6):
287319 GenerateXml (file_name ,image .shape ,result ["boxes" ],result ["labels" ],save_anno_path )
288320 processBar .update ()
289321
322+
323+
290324if __name__ == '__main__' :
291- jadeVOCDatasets = JadeVOCDatasets (r'F:\数据集 \VOC数据集\定制版顶相机箱号检测数据集 ' )
325+ jadeVOCDatasets = JadeVOCDatasets (r'E:\Data \VOC数据集\箱门检测数据集\ContainVOC ' )
292326 # jadeVOCDatasets.remove_no_labels()
293- jadeVOCDatasets .change_labels ([ "PCTNNO" , "NCTNNO" ], "CTNNO" )
327+ jadeVOCDatasets .VOCDatasetToYoloDatasets ( )
0 commit comments