agametov / opencv-video-stream-with-face-recognition Goto Github PK
View Code? Open in Web Editor NEWStreaming video with face recognition
License: The Unlicense
Streaming video with face recognition
License: The Unlicense
Hi, I'm making a web site using your flask example in a raspberry pi. Everything works except that is not drawing the rectangle and any other graphic make for openCV. Your example works perfect when I run it, but the problem is that it works slowly. What can be the reason? This is my code:
#!/usr/bin/python import numpy as np import cv2 import os import time face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
`class Camera(object):
def init(self):
# Set the font style
os.system("sudo modprobe bcm2835-v4l2")
self.video = cv2.VideoCapture(0)
if not self.video.isOpened():
raise RuntimeError("Could not start camera.")`
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
faces = face_cascade.detectMultiScale(image, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.putText(image, 'unknown', (x - 10, y - 10), cv2.FONT_HERSHEY_PLAIN,
1,(0, 255, 0))
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes() `
And this is the page:
`{% extends 'base.html' %}
{% block content %}
{% endblock %}`
And this is the mapping of the flask server:
`@app.route('/video')
def video():
if 'username' in session:
return render_template('video.html')
else:
return redirect(url_for('login'))
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')`
Please help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.