-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_structuring.py
More file actions
62 lines (39 loc) · 1.4 KB
/
data_structuring.py
File metadata and controls
62 lines (39 loc) · 1.4 KB
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
# coding: utf-8
# In[ ]:
import cv2
import numpy
import glob
import os
from PIL import Image
from os import listdir
from os.path import isfile, join
import pandas as pd
# In[ ]:
counter = 1000
root = '' #path from where training data logo images need to collected
dest = 'training_data/' # folder where images are organized according to brand they represent
onlyfiles = [f for f in listdir(root) if isfile(join(root, f))]
images = [cv2.imread(file) for file in glob.glob(root + '/*jpg')]
# In[ ]:
with open('flickr_logos_27_dataset/flickr_logos_27_dataset_query_set_annotation.txt', 'r') as f:
lines = f.readlines()
# remove spaces
#lines = [line.replace(' ', '') for line in lines]
# finally, write lines in the file
#with open('flickr_logos_27_dataset/flickr_logos_27_dataset_training_set_annotation.txt', 'w') as f:
#f.writelines(lines)
data = pd.read_csv('flickr_logos_27_dataset/flickr_logos_27_dataset_query_set_annotation.txt', sep="\t", header=None)
# In[ ]:
for f in onlyfiles:
for ID in data[0]:
if f==ID:
loc_txt_file = list(data[0]).index(f)
loc_root = list(onlyfiles).index(f)
img_name = data.iloc[b][1]+'/'+f
k = os.path.join(dest,img_name)
print(k)
cv2.imwrite(k, images[loc_root])
try:
os.remove(root + '/' + f)
except:
pass