-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate_data.py
58 lines (51 loc) · 1.41 KB
/
generate_data.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
import cv2
import matplotlib.pyplot as plt
from os import (
listdir,
path,
)
import pickle
import sqlite3 as sqlite
def main():
dirpath = path.dirname(path.abspath('__file__'))
img_list = listdir(
path.join(
dirpath,
'Thistles/jer_2016jan13n15/barley_30m/output_barley_30m/'))
# build one connection to db file
con = sqlite.connect('barley_30m.db')
c = con.cursor()
print('creating table...')
c.execute(
'''
create table img(
id INTEGER PRIMARY KEY AUTOINCREMENT not null,
rgb,
hsv,
label
);
'''
)
print('table has been created')
# import the images data
for img_name in img_list:
if not 'surround' in img_name:
rgb = plt.imread(
path.join(
'Thistles/jer_2016jan13n15/barley_30m/output_barley_30m/',
img_name
)).astype('float32')
hsv = cv2.cvtColor(rgb,cv2.COLOR_BGR2HSV)
if 'uc' in img_name:
label = 1
else:
label = 0
c.execute(
'insert into img(rgb, hsv, label) values(?, ?, ?)',
(pickle.dumps(rgb), pickle.dumps(hsv), label)
)
print('Inserting img: {}'.format(img_name))
con.commit()
con.close()
if __name__ == '__main__':
main()