forked from AlexeyAB/darknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmAP_copy_images_to_dir.py
38 lines (33 loc) · 1.01 KB
/
mAP_copy_images_to_dir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
@ Author: Yu-Hsien Liao (LiaoSteve)
@ Date: 2021/01/09
@ Description: copy the validation set to \n
'mAP/input/images-optional' dir to calculate the mAP
'''
import cv2
import os
from pathlib import Path
from tqdm import tqdm
data_path = Path('data/obj.data')
output_image_dir = Path('mAP/input/images-optional')
os.makedirs(output_image_dir, exist_ok=True)
# get the images path from .data file
with open(data_path,'r') as f:
data = f.readlines()
for line in data:
if 'valid' in line:
data = line.split(' ')[-1]
data = data.split('\n')[0]
break
# get all image path
with open(data,'r') as f:
image_list = f.readlines()
for i in tqdm(range(len(image_list))):
image = image_list[i]
image = image.split('\n')[0]
frame = cv2.imread(str(image))
path, name = os.path.split(image)
name, _ = name.split('.')
name = name + '.jpg'
cv2.imwrite(str(output_image_dir/Path(name)), frame, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
print('Done')