Skip to content

Commit fbffc9a

Browse files
committed
feat(data): 解析定位数据集,分离图像和标注文件
1 parent dfa83fa commit fbffc9a

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

py/lib/data/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
@date: 2020/4/16 上午10:49
5+
@file: __init__.py.py
6+
@author: zj
7+
@description:
8+
"""

py/lib/data/parse_location.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
@date: 2020/4/21 下午1:30
5+
@file: parse_location.py
6+
@author: zj
7+
@description: 解析定位数据集,分别保存图像和标注数据
8+
"""
9+
10+
import os
11+
import shutil
12+
import glob
13+
14+
from utils import util
15+
16+
17+
def pretreat():
18+
"""
19+
判断源文件目录是否为空
20+
清空结果文件目录,并新建图像和标注文件夹
21+
:return:
22+
"""
23+
src_root_dir = '../../data/training_images'
24+
dst_root_dir = '../../data/location_dataset'
25+
26+
if not os.path.exists(src_root_dir):
27+
util.error("%s doesn't exist" % src_root_dir)
28+
if os.path.exists(dst_root_dir):
29+
shutil.rmtree(dst_root_dir)
30+
os.mkdir(dst_root_dir)
31+
32+
dst_img_dir = os.path.join(dst_root_dir, 'imgs')
33+
dst_annotation_dir = os.path.join(dst_root_dir, 'annotations')
34+
os.mkdir(dst_img_dir)
35+
os.mkdir(dst_annotation_dir)
36+
37+
return src_root_dir, dst_root_dir, dst_img_dir, dst_annotation_dir
38+
39+
40+
if __name__ == '__main__':
41+
src_root_dir, dst_root_dir, dst_img_dir, dst_annotation_dir = pretreat()
42+
43+
img_path_list = glob.glob(os.path.join(src_root_dir, '*.jpg'))
44+
annotation_path_list = glob.glob(os.path.join(src_root_dir, '*.xml'))
45+
46+
for img_path in img_path_list:
47+
dst_img_path = os.path.join(dst_img_dir, os.path.basename(img_path))
48+
shutil.copyfile(img_path, dst_img_path)
49+
50+
for annotation_path in annotation_path_list:
51+
dst_annotation_path = os.path.join(dst_annotation_dir, os.path.basename(annotation_path))
52+
shutil.copyfile(annotation_path, dst_annotation_path)

0 commit comments

Comments
 (0)