-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.py
executable file
·94 lines (82 loc) · 2.57 KB
/
app.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import eel
import os
import random
import cv2
import os
import numpy as np
import label_image
eel.init('web')
@eel.expose # Expose this function to Javascript
def handleinput(name):
#name = input("Enter the classifier name\n")
path = "images/"+name
if not os.path.isdir('images'):
os.mkdir('images')
try:
os.mkdir(path)
print("Folder created for : ",name,"\n")
except:
pass
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
eel.info("Press Q to stop taking pictures")
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,1)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
vidcap = cv2.VideoCapture('output.avi')
success,image = vidcap.read()
count = 0
success = True
while success:
success,image = vidcap.read()
if(success==True):
cv2.imwrite('images/'+name+'/frame%d.jpg' % count, image) # save frame as JPEG file
print('Read a new frame: ', success)
count += 1
else:
pass # Expose this function to Javascript
eel.info("succesfully saved for "+name)
#os.system("rm output.avi")
@eel.expose
def detect_faces():
print('detection started')
eel.info("Press ESC to stop")
size = 4
webcam = cv2.VideoCapture(0)
while True:
(rval, im) = webcam.read()
im=cv2.flip(im,1,0)
mini = cv2.resize(im, (int(im.shape[1]/size), int(im.shape[0]/size)))
cv2.imwrite('testimage.jpg',im)
testimage = "testimage.jpg"
text = label_image.main(testimage)
text = text.title()
font = cv2.FONT_HERSHEY_TRIPLEX
cv2.putText(im, text,(100,100), font, 2, (0,255,0), 2)
cv2.imshow('Capture', im)
key = cv2.waitKey(10)
if key == 27:
break
@eel.expose
def train_images():
eel.info("Seat Back and wait.....")
eel.mSpinner()
try:
os.system('python3 retrain.py --output_graph=retrained_graph.pb --output_labels=retrained_labels.txt --architecture=MobileNet_1.0_224 --image_dir=images')
eel.info("Training is completed")
eel.mSpinner()
eel.mAddTick()
except:
eel.info("connect to internet..")
eel.start('main2.html', size=(700, 400))