-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetAllImages.py
61 lines (43 loc) · 1.49 KB
/
getAllImages.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import csv
import json
import sys
import wget
from termcolor import colored
import requests
pathDataset = 'dataset-exported.csv'
dirImageLabel = 'imageLabel'
dirMaskImage = 'maskLabel'
prefixNameImage = 'fc_road_'
extPng = '.png'
extJpg = '.jpg'
zerosLeft = 5
if os.path.exists(dirImageLabel):
os.rmdir(dirImageLabel)
if os.path.exists(dirMaskImage):
os.rmdir(dirMaskImage)
os.makedirs(dirImageLabel)
os.makedirs(dirMaskImage)
with open(pathDataset) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
count_row = 0
for row in csv_reader:
if count_row == 0:
print(colored(row,'green'))
else:
link_raw_image = row[2]
link_mask_image = json.loads(row[17])['Road']
print(colored(f"Image: {prefixNameImage}{str(count_row).zfill(5)}{extPng}",'yellow'))
imageName = f"{prefixNameImage}{str(count_row).zfill(5)}{extJpg}"
pathSave = os.path.join(dirImageLabel, imageName)
stream = requests.get(link_raw_image)
with open(pathSave, 'wb') as f:
f.write(stream.content)
imageName = f"{prefixNameImage}{str(count_row).zfill(zerosLeft)}{extPng}"
pathSave = os.path.join(dirMaskImage, imageName)
stream = requests.get(link_mask_image)
with open(pathSave, 'wb') as f:
f.write(stream.content)
count_row+=1
print(100*"*")
print("END")