示例#1
0
 def __init__(self,
              label_root,
              image_root,
              classes=get_classes('dota'),
              path_replace=None,
              box_form='x1y1wh'):
     self.label_root = label_root
     self.image_root = image_root
     self.path_replace = path_replace
     self.box_form = box_form
     self.files = []
     self.files += cvtools.get_files_list(label_root, basename=True)
     if cvtools._DEBUG:
         self.files = self.files[:10]
     self.lines = []
     if isinstance(classes, str):
         self.cls_map = cvtools.read_key_value(classes)
     else:
         self.cls_map = {name: i + 1 for i, name in enumerate(classes)}
     self.coco_dataset = {
         "info": {
             "description": "This is stable 1.0 version of the DOTA.",
             "url": "http://captain.whu.edu.cn/DOTAweb/index.html",
             "version": "1.0",
             "year": 2018,
             "contributor": "DOTA",
             "date_created": cvtools.get_time_str()
         },
         "categories": [],
         "images": [],
         "annotations": []
     }
     self.imageID = 1
     self.annID = 1
     self.run_timer = cvtools.Timer()
示例#2
0
 def __init__(self,
              path,
              cls_map='arcsoft/cat_id_map.txt',
              path_replace=None,
              img_suffix='.jpg'):
     self.path = path
     self.path_replace = path_replace
     self.img_suffix = img_suffix
     self.txt_list = cvtools.get_files_list(self.path,
                                            file_type='.txt',
                                            basename=True)
     # you could comment this two sentences if you don't want check integrity
     # of images and labels.
     # self.img_list = cvtools.get_files_list(
     #     self.path, file_type=img_suffix)
     # assert len(self.img_list) == len(self.txt_list)
     self.cls_map = cvtools.read_key_value(cls_map)
     self.coco_dataset = {
         "info": {
             "description": "Open Dataset.",
             "url": "http://www.arcsoft.com",
             "version": "1.0",
             "year": 2019,
             "contributor": "arcsoft",
             "date_created": cvtools.get_time_str()
         },
         "categories": [],  # Not added yet
         "images": [],
         "annotations": []
     }
     self.imageID = 1
     self.annID = 1
     self.run_timer = cvtools.Timer()
示例#3
0
 def create_uuid(self):
     # 生成当前时间
     now_time = cvtools.get_time_str("%Y%m%d%H%M%S")
     random_num = random.randint(0, 100)  # 生成的随机整数n,其中0<=n<=100
     if random_num <= 10:
         random_num = str(0) + str(random_num)
     return now_time + str(random_num)
示例#4
0
def save_image(filename, img, results=None):
    img_name = cvtools.get_time_str(form='%Y%m%d_%H%M%S_%f') + '.jpg'
    if filename:
        filename = filename.replace('\\', '/')
        if cvtools.is_image_file(filename):
            img_name = osp.basename(filename)
    img_file = osp.join(log_save_root, 'images', img_name)
    try:
        logger.info("filename: {}, saving image in {}".format(
            filename, img_file))
        if results:
            logger.info("detect results: {}".format(results))
        cvtools.imwrite(img, img_file)
    except Exception as e:
        logger.error(e)
示例#5
0
    def __init__(self,
                 root,
                 mode='train',
                 cls=get_classes('voc'),
                 cls_replace=None,
                 use_xml_name=True,
                 read_test=False):
        self.root = root
        self.mode = mode
        self.cls_replace = cls_replace
        self.use_xml_name = use_xml_name
        self.read_test = read_test
        if isinstance(cls, str):
            self.voc_classes = cvtools.read_files_to_list(cls)
        else:
            self.voc_classes = cls
        self.cls_map = {name: i + 1 for i, name in enumerate(self.voc_classes)}

        file = osp.join(root, 'ImageSets/Main/{}.txt'.format(mode))
        self.imgs = cvtools.read_files_to_list(file)
        self.img_paths = [
            'JPEGImages/{}.jpg'.format(img_name)  # relative path
            for img_name in self.imgs
        ]
        self.xml_paths = [
            osp.join(root, 'Annotations/{}.xml'.format(img_name))
            for img_name in self.imgs
        ]

        # coco format dataset definition
        self.coco_dataset = {
            "info": {
                "description": "The PASCAL Visual Object Classes.",
                "url": "http://host.robots.ox.ac.uk/pascal/VOC/",
                "version": "1.0",
                "year": 2007,
                "contributor": "VOC",
                "date_created": cvtools.get_time_str()
            },
            "categories": [],
            "images": [],
            "annotations": []
        }
        self.imageID = 1
        self.annID = 1
示例#6
0
def test_get_time_str():
    print(cvtools.get_time_str())
    print(cvtools.get_time_str(form='%Y-%m-%d %H:%M:%S.%f'))
    print(cvtools.get_time_str(form='%Y%m%d_%H%M%S_%f'))