-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhweb.py
More file actions
72 lines (61 loc) · 2.1 KB
/
hweb.py
File metadata and controls
72 lines (61 loc) · 2.1 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
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, render_template, redirect, url_for, request,session
import cv2
import os
import face_recognition
import glob
import numpy as np
from PIL import Image, ImageDraw
app=Flask(__name__)
app.secret_key = 'dljsaklqk24e21cjn!Ew@@dsa5'
@app.route('/')
def home():
return "apoorav"
@app.route('/start', methods=['GET'])
def hunny():
error=None
return render_template('start.html', error=error)
@app.route('/start', methods=['POST'])
def start():
error=None
cam = cv2.VideoCapture(0)
cv2.namedWindow("F:\hackathon\Test")
img_counter = 0
while True:
ret, frame = cam.read()
cv2.imshow("F:\hackathon\Test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
print("Escape hit, closing...")
break
elif k%256 == 32:
a=1;
img_name = "opencv_frame_{}.png".format(img_counter)
path = 'F:\hackathon\Test/'
cv2.imwrite(os.path.join(path , img_name), frame)
print("{} written!".format(img_name))
img_counter += 1
if a==1:
break;
cam.release()
cv2.destroyAllWindows()
os.chdir("F:\hackathon\Test")
path2 = 'F:\hackathon/'
for images in glob.glob("*.png"):
image_name=images
image=face_recognition.load_image_file(images)
face_locations = face_recognition.face_locations(image)
#test_face = face_recognition.face_encodings(image, face_locations)
pil_image = Image.fromarray(image)
draw = ImageDraw.Draw(pil_image)
for (top, right, bottom, left) in face_locations:
draw.rectangle(((left, top), (right, bottom)), outline=(0, 0, 255))
# print(image[left:right][top:bottom])
x=image[top:bottom,left:right]
pil_image.show()
cv2.imwrite(os.path.join(path2 , "face.jpg"), x)
redirect(url_for('start'))
return render_template('start.html', error=error)
if __name__ == "__main__":
app.run(debug=True)