Spaces:
No application file
No application file
upload documents
Browse files- Haarcascades/haarcascade_eye.xml +0 -0
- Haarcascades/haarcascade_frontalface_default.xml +0 -0
- app.py +52 -0
- templates/index.html +37 -0
- templates/stop.html +25 -0
Haarcascades/haarcascade_eye.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Haarcascades/haarcascade_frontalface_default.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, Response
|
| 2 |
+
import cv2
|
| 3 |
+
app=Flask(__name__)
|
| 4 |
+
|
| 5 |
+
def capture_by_frames():
|
| 6 |
+
global camera
|
| 7 |
+
camera = cv2.VideoCapture(0)
|
| 8 |
+
while True:
|
| 9 |
+
success, frame = camera.read() # read the camera frame
|
| 10 |
+
detector=cv2.CascadeClassifier('C:\\Python39\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml')
|
| 11 |
+
faces=detector.detectMultiScale(frame,1.2,6)
|
| 12 |
+
|
| 13 |
+
#Draw the rectangle around each face
|
| 14 |
+
# for (x, y, w, h) in faces:
|
| 15 |
+
# cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 3)
|
| 16 |
+
|
| 17 |
+
eye_cascade = cv2.CascadeClassifier('C:\\Python39\\Lib\\site-packages\\cv2\\data\\haarcascade_eye.xml')
|
| 18 |
+
faces=detector.detectMultiScale(frame,1.1,7)
|
| 19 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 20 |
+
#Draw the rectangle around each face
|
| 21 |
+
for (x, y, w, h) in faces:
|
| 22 |
+
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
|
| 23 |
+
roi_gray = gray[y:y+h, x:x+w]
|
| 24 |
+
roi_color = frame[y:y+h, x:x+w]
|
| 25 |
+
eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 3)
|
| 26 |
+
for (ex, ey, ew, eh) in eyes:
|
| 27 |
+
cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)
|
| 28 |
+
|
| 29 |
+
ret, buffer = cv2.imencode('.jpg', frame)
|
| 30 |
+
frame = buffer.tobytes()
|
| 31 |
+
yield (b'--frame\r\n'
|
| 32 |
+
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
|
| 33 |
+
|
| 34 |
+
@app.route('/')
|
| 35 |
+
def index():
|
| 36 |
+
return render_template('index.html')
|
| 37 |
+
|
| 38 |
+
@app.route('/start',methods=['POST'])
|
| 39 |
+
def start():
|
| 40 |
+
return render_template('index.html')
|
| 41 |
+
|
| 42 |
+
@app.route('/stop',methods=['POST'])
|
| 43 |
+
def stop():
|
| 44 |
+
if camera.isOpened():
|
| 45 |
+
camera.release()
|
| 46 |
+
return render_template('stop.html')
|
| 47 |
+
|
| 48 |
+
@app.route('/video_capture')
|
| 49 |
+
def video_capture():
|
| 50 |
+
return Response(capture_by_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
| 51 |
+
if __name__=='__main__':
|
| 52 |
+
app.run(debug=True,use_reloader=False, port=8000)
|
templates/index.html
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
| 4 |
+
<title>Chetan Sunil Khairnar - Face Detection</title>
|
| 5 |
+
<style>
|
| 6 |
+
h2 {
|
| 7 |
+
padding-bottom: 20px;
|
| 8 |
+
font-weight: 600;
|
| 9 |
+
font-size: 3.2em
|
| 10 |
+
}
|
| 11 |
+
</style>
|
| 12 |
+
|
| 13 |
+
<body>
|
| 14 |
+
<div class="container">
|
| 15 |
+
<center>
|
| 16 |
+
<h2>Face-Eye Detection System</h2>
|
| 17 |
+
</center>
|
| 18 |
+
<div class="col-lg-offset-2 col-lg-8">
|
| 19 |
+
<center>
|
| 20 |
+
<form class="form-inline" action="/stop" method="post" enctype="multipart/form-data">
|
| 21 |
+
<input type="submit" class="btn btn-danger btn-md btn-block" value="Stop">
|
| 22 |
+
</form>
|
| 23 |
+
</center>
|
| 24 |
+
<center>
|
| 25 |
+
<form class="form-inline" action="/start" method="post" enctype="multipart/form-data">
|
| 26 |
+
<input type="submit" class="btn btn-success btn-md btn-block" value="Start">
|
| 27 |
+
</form>
|
| 28 |
+
</center><br>
|
| 29 |
+
</div>
|
| 30 |
+
<div class="col-lg-offset-2 col-lg-8">
|
| 31 |
+
<img src="{{ url_for('video_capture') }}" width="100%">
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
</div>
|
| 35 |
+
</body>
|
| 36 |
+
|
| 37 |
+
</html>
|
templates/stop.html
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
| 4 |
+
<title> Chetan Sunil Khairnar - Face Detection</title>
|
| 5 |
+
<style>
|
| 6 |
+
h2
|
| 7 |
+
{
|
| 8 |
+
padding-bottom:20px;
|
| 9 |
+
font-weight: 600;
|
| 10 |
+
font-size: 3.2em
|
| 11 |
+
}
|
| 12 |
+
</style>
|
| 13 |
+
<body>
|
| 14 |
+
<div class="container">
|
| 15 |
+
<center><h2>Face Detection</h2></center>
|
| 16 |
+
<div class="col-lg-offset-2 col-lg-8">
|
| 17 |
+
<center><form class="form-inline" action = "/stop" method = "post" enctype="multipart/form-data">
|
| 18 |
+
<input type = "submit" class="btn btn-danger btn-md btn-block" value="Stop">
|
| 19 |
+
</form></center>
|
| 20 |
+
<center><form class="form-inline" action = "/start" method = "post" enctype="multipart/form-data">
|
| 21 |
+
<input type = "submit" class="btn btn-success btn-md btn-block" value="Start">
|
| 22 |
+
</form></center><br>
|
| 23 |
+
</div></div>
|
| 24 |
+
</body>
|
| 25 |
+
</html>
|