Coder Social home page Coder Social logo

agametov / opencv-video-stream-with-face-recognition Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 10.0 141 KB

Streaming video with face recognition

License: The Unlicense

Python 91.09% HTML 8.91%
opencv face-detection webcam python video-stream streaming-video

opencv-video-stream-with-face-recognition's Introduction

Video stream with face recognition on OpenCV

1. Install Python dependencies: cv2, flask. (wish that pip install works like a charm)

2. Run "python main.py".

3. Navigate the browser to the local webpage.

opencv-video-stream-with-face-recognition's People

Contributors

agametov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

opencv-video-stream-with-face-recognition's Issues

cv2.rectangle is not drawing

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 %}

Face recognition

{% 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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.