-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv_collect.py
54 lines (48 loc) · 1.74 KB
/
cv_collect.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
from SimpleCV import *
import sys
import os, os.path
import time
from cv_run import shade_cards, get_grid, split_image
base_path = "/home/nikita/Desktop/classifier"
def save_training(images, tag):
if not os.path.exists(os.path.join(base_path, tag)):
if tag.startswith("test/") and not os.path.exists(os.path.join(base_path, "test")):
os.mkdir(os.path.join(base_path, "test"))
os.mkdir(os.path.join(base_path, tag))
n = 0
for row in images:
for img in row:
img.save(os.path.join(base_path, tag, "{}-{}.png".format(int(time.time()), n)))
n += 1
def main(tag):
disp = Display((640, 360), title="Collect")
top_row = []
bottom_row = []
blobs = []
img = None
while disp.isNotDone():
if disp.mouseRight:
img = cam.getImage().scale(640, 360)
elif disp.mouseMiddle and img is not None:
try:
top_row, bottom_row, blobs = get_grid(img)
except IndexError:
img.dl().rectangle([0, 0], [640, 360], color=Color.RED, filled=True, alpha=150)
elif disp.mouseLeft and img is not None:
images = split_image(img, top_row, bottom_row)
save_training(images, tag)
img.dl().rectangle([0, 0], [640, 360], color=Color.BLACK, filled=True, alpha=200)
img.save(disp)
img = None
if img is not None:
shade_cards(img, top_row, bottom_row, 90)
img.save(disp)
img.clearLayers()
disp.quit()
if __name__ == '__main__':
if len(sys.argv) != 2:
print """usage: python cv_collect.py tag"""
else:
# TODO: camera start is buggy because the index changes
cam = Camera(2)
main(sys.argv[1])