-
Notifications
You must be signed in to change notification settings - Fork 0
/
take_dataset.py
65 lines (50 loc) · 1.18 KB
/
take_dataset.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
62
63
64
65
import os
import time
import datetime as dt
from pynput import keyboard
import tkinter as tk
import cv2
from gui import Application
first = os.getcwd()
try:
os.chdir('JPEGImages')
except:
os.mkdir('JPEGImages')
os.chdir(first)
root = tk.Tk()
app = Application(master=root, width=1920, height=1080, bg='white')
cam = cv2.VideoCapture("/dev/video0")
take = False
flag = True
def checkKey(key):
global take
try:
if key == keyboard.Key.space:
take = True
except AttributeError:
pass
def releaseKey(key):
global take
take = False
start = 0
def mainLoop():
global take, flag, start
ret, frame = cam.read()
#checkKey()
if take:
if flag:
Timetake = dt.datetime.now().strftime("JPEGImages/%Y%m%d-%H%M%S.jpg")
cv2.imwrite(Timetake, frame)
start = time.time()
flag = False
else:
flag = True
if (time.time()-start)<3:
app.showThankyou()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
app.loop(frame,True)
root.after(1,mainLoop)
listener = keyboard.Listener(on_press=checkKey, on_release=releaseKey)
listener.start()
mainLoop()
root.mainloop()