Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple cameras
#1
Hello all,

I am trying to create flask based app in which, every logged in user would have live stream view. For now everything works fine, however I want to add new feature, thanks to which, user would disable face detection.

Currently my code looks like this:
from flask import Blueprint, render_template, Response, abort
from flask_login import login_required, current_user
from . import db

import cv2
import cvlib as cv

main = Blueprint('main', __name__)

camera = cv2.VideoCapture(0)

def detectFace(img):
    faces, confidences = cv.detect_face(img)

    for face in faces:
        (startX, startY) = face[0], face[1]
        (endX, endY) = face[2], face[3]

        cv2.rectangle(img, (startX, startY), (endX, endY), (0, 255, 0), 2)

    return img

def gen(camera):
    while True:
        rval, frame = camera.read()
        frame = cv2.resize(frame, (640, 480))

        frame = detectFace(frame)

        cv2.imwrite('t.jpg', frame)
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + open('t.jpg', 'rb').read() + b'\r\n')

@main.route('/')
def index():
    return render_template('index.html')

@main.route('/profile')
def profile():
    if not current_user.is_authenticated:
        abort(403)
    
    return render_template('profile.html', name=current_user.name)

@main.route("/video_stream")
def video_stream():
    if not current_user.is_authenticated:
        abort(403)

    global camera
    return Response(gen(camera), mimetype='multipart/x-mixed-replace; boundary=frame')

@main.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

@main.errorhandler(403)
def page_forbidden(e):
    return render_template('403.html'), 403
For now I have no idea how to implement this is such way that, when user A would like to turn off detection, it will be disable for him but other users will still have it.

Any help? Angel
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020