# -*- coding: utf-8 -*- # -*- author: jokker -*- import random import os import shutil import cv2 import PIL.Image as Image from JoTools.operateDeteRes import OperateDeteRes from JoTools.txkjRes.deteRes import DeteRes, DeteObj from JoTools.utils.FileOperationUtil import FileOperationUtil from JoTools.utils.RandomUtil import RandomUtil xml_dir = r"/home/ldq/tj_dete/merge" save_dir = r"/home/ldq/tj_dete/merge_new" OperateDeteRes.get_class_count(xml_dir, print_count=True) for each_xml_path in FileOperationUtil.re_all_file(xml_dir, endswitch=['.xml']): # a = DeteRes(each_xml_path) a.filter_by_tags(need_tag=["2"]) save_path = os.path.join(save_dir, os.path.split(each_xml_path)[1]) if len(a) > 0: a.save_to_xml(save_path) OperateDeteRes.get_class_count(save_dir, print_count=True)
y1 = int(each_comment['y']) x2 = int(each_comment['width']) + x1 y2 = int(each_comment['height']) + y1 tag = str(each_comment['annotation']).split('_')[0] b.add_obj(x1, y1, x2, y2, tag=tag, conf=-1) if b.has_tag('040303021') or b.has_tag('040303022'): # 存在防振锤,需要进行复制文件 each_xml_name = os.path.split(b.file_name)[1][:-3] + 'xml' each_save_img_name = os.path.split(b.file_name)[1][:-3] + 'jpg' each_xml_path = os.path.join(save_dir, each_xml_name) each_save_img_path = os.path.join(save_dir, each_save_img_name) # print(each_xml_path) # print(each_save_img_path) b.filter_by_tags(need_tag=[ '040303021', '040303022', '040303000', '040303011', '040303031', '040303041' ]) b.save_to_xml(each_xml_path) shutil.copy(b.img_path, each_save_img_path) # b.crop_and_save(r"C:\Users\14271\Desktop\del\crop", split_by_tag=True, include_tag_list=assign_code_list, augment_parameter=[0.1,0.1,0.1,0.1]) except Exception as e: print(e) # print(a.name) # print(a.comments)