nisharg nargund commited on
Commit ·
31b916c
1
Parent(s): 8ac31e1
Upload 6 files
Browse files- app.py +40 -0
- haarcascade_eye.xml +0 -0
- haarcascade_frontalface_default.xml +0 -0
- index.html +17 -0
- main.py +33 -0
- result.html +18 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
from flask import Flask, render_template, Response
|
| 4 |
+
import cv2
|
| 5 |
+
app=Flask(__name__)
|
| 6 |
+
camera = cv2.VideoCapture(0)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def frames():
|
| 10 |
+
while True:
|
| 11 |
+
success, frame = camera.read() # read the camera frame
|
| 12 |
+
if not success:
|
| 13 |
+
break
|
| 14 |
+
else:
|
| 15 |
+
detector=cv2.CascadeClassifier('cascadesxml\haarcascade_frontalface_default.xml')
|
| 16 |
+
eye_cascade = cv2.CascadeClassifier('cascadesxml\haarcascade_eye.xml')
|
| 17 |
+
faces=detector.detectMultiScale(frame,1.1,7)
|
| 18 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 19 |
+
#Draw the rectangle around each face
|
| 20 |
+
for (x, y, w, h) in faces:
|
| 21 |
+
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 255), 2)
|
| 22 |
+
roi_gray = gray[y:y+h, x:x+w]
|
| 23 |
+
roi_color = frame[y:y+h, x:x+w]
|
| 24 |
+
eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3)
|
| 25 |
+
for (ex, ey, ew, eh) in eyes:
|
| 26 |
+
cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (255, 255, 0), 2)
|
| 27 |
+
|
| 28 |
+
ret, buffer = cv2.imencode('.jpg', frame)
|
| 29 |
+
frame = buffer.tobytes()
|
| 30 |
+
yield (b'--frame\r\n'
|
| 31 |
+
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
|
| 32 |
+
|
| 33 |
+
@app.route('/')
|
| 34 |
+
def index():
|
| 35 |
+
return render_template('index.html')
|
| 36 |
+
@app.route('/video_feed')
|
| 37 |
+
def video_feed():
|
| 38 |
+
return Response(frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
| 39 |
+
if __name__=='__main__':
|
| 40 |
+
app.run(debug=True)
|
haarcascade_eye.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
haarcascade_frontalface_default.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
index.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
<body>
|
| 6 |
+
<div class="container">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-8 offset-lg-2">
|
| 9 |
+
<center><h3 class="mt-5">Live Face and Eye Detection</h3></center>
|
| 10 |
+
<img src="{{ url_for('video_feed') }}" width="50%">
|
| 11 |
+
</div>
|
| 12 |
+
</div>
|
| 13 |
+
</div>
|
| 14 |
+
</body>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
</html>
|
main.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
from flask import Flask, render_template, Response
|
| 4 |
+
import cv2
|
| 5 |
+
app=Flask(__name__)
|
| 6 |
+
camera = cv2.VideoCapture(0)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def gen():
|
| 10 |
+
while True:
|
| 11 |
+
success, frame = camera.read() # read the camera frame
|
| 12 |
+
if not success:
|
| 13 |
+
break
|
| 14 |
+
else:
|
| 15 |
+
detector=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
| 16 |
+
faces=detector.detectMultiScale(frame,1.1,7)
|
| 17 |
+
#Draw the rectangle around each face
|
| 18 |
+
for (x, y, w, h) in faces:
|
| 19 |
+
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
|
| 20 |
+
|
| 21 |
+
ret, buffer = cv2.imencode('.jpg', frame)
|
| 22 |
+
frame = buffer.tobytes()
|
| 23 |
+
yield (b'--frame\r\n'
|
| 24 |
+
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
|
| 25 |
+
|
| 26 |
+
@app.route('/')
|
| 27 |
+
def index():
|
| 28 |
+
return render_template('index.html')
|
| 29 |
+
@app.route('/video_feed')
|
| 30 |
+
def video_feed():
|
| 31 |
+
return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
| 32 |
+
if __name__=='__main__':
|
| 33 |
+
app.run(debug=True)
|
result.html
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<html>
|
| 2 |
+
|
| 3 |
+
<h2>Final Results</h2>
|
| 4 |
+
|
| 5 |
+
<body>
|
| 6 |
+
<table border=2>
|
| 7 |
+
{% for key,value in result.items() %}
|
| 8 |
+
<tr>
|
| 9 |
+
{# This is the comment sections #}
|
| 10 |
+
<th>{{ key }}</th>
|
| 11 |
+
<th>{{ value }}</th>
|
| 12 |
+
|
| 13 |
+
</tr>
|
| 14 |
+
{% endfor %}
|
| 15 |
+
</table>
|
| 16 |
+
</body>
|
| 17 |
+
|
| 18 |
+
</html>
|