实施人脸检测时视频流滞后
Videostreaming is lagging when implementing facedetection
我正在使用 Rapberry Pi 在网络服务器中播放视频流。
视频流还可以,但是一旦我实现人脸识别,它就会很卡。
这是我的代码:
from flask import Flask, render_template, Response
import cv2
import argparse
from imutils.video import VideoStream
import imutils
import subprocess
app = Flask(__name__)
# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
vs = VideoStream(usePiCamera=1).start()
def gen_frames(): # generate frame by frame from camera
while True:
# Capture frame-by-frame
global vs
frame = vs.read() # read the camera frame
frame = imutils.resize(frame, width=800)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
#Draw the rectangle around each face
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
@app.route('/video_feed')
def video_feed():
#Video streaming route. Put this in the src attribute of an img tag
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
def videostreaming():
# start the flask app
app.run(host="192.168.0.33",port=8000, debug=True,use_reloader=False)
videostreaming()
有没有办法通过面部检测功能使视频流更流畅?
似乎是视频的宽度导致我的视频流出现问题。只需将其减少到 500 以使其更平滑。
发件人:
frame = imutils.resize(frame, width=800)
收件人:
frame = imutils.resize(frame, width=500)
我正在使用 Rapberry Pi 在网络服务器中播放视频流。
视频流还可以,但是一旦我实现人脸识别,它就会很卡。
这是我的代码:
from flask import Flask, render_template, Response
import cv2
import argparse
from imutils.video import VideoStream
import imutils
import subprocess
app = Flask(__name__)
# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
vs = VideoStream(usePiCamera=1).start()
def gen_frames(): # generate frame by frame from camera
while True:
# Capture frame-by-frame
global vs
frame = vs.read() # read the camera frame
frame = imutils.resize(frame, width=800)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect the faces
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
#Draw the rectangle around each face
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
@app.route('/video_feed')
def video_feed():
#Video streaming route. Put this in the src attribute of an img tag
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
def videostreaming():
# start the flask app
app.run(host="192.168.0.33",port=8000, debug=True,use_reloader=False)
videostreaming()
有没有办法通过面部检测功能使视频流更流畅?
似乎是视频的宽度导致我的视频流出现问题。只需将其减少到 500 以使其更平滑。
发件人:
frame = imutils.resize(frame, width=800)
收件人:
frame = imutils.resize(frame, width=500)