Я пытаюсь настроить видеопоток с моей камеры Raspberry Pi на мой веб-сервер с помощью Flask.Все отлично работает с веб-сервером Flask, но после использования apache с flask выдает ошибку.
error: /build/opencv-U1UwfN/opencv-2.4.9.1+dfsg1/modules/highgui/src/grfmt_base.cpp:131: error: (-10) Raw image encoder error: Empty JPEG image (DNL not supported) in function throwOnEror
Мой код Python выглядит следующим образом
if session["logged_in"] == True:
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
Gen:
def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
Модуль камеры
import cv2
class VideoCamera(object):
def __init__(self):
# Using OpenCV to capture from device 0. If you have trouble capturing
# from a webcam, comment the line below out and use a video file
# instead.
self.video = cv2.VideoCapture(0)
# If you decide to use video.mp4, you must have this file in the folder
# as the main.py.
# self.video = cv2.VideoCapture('video.mp4')
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
if not success:
print("WARNING #### No Camera Device available #### WARNING")
cv2.imwrite("/static/images/camerapic.png", image)
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
Файл Apache WSGI
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")
from flaskapp import app as application
application.secret_key = 'key'
Файл конфигурации Apache
<VirtualHost *>
ServerName example.com
WSGIScriptAlias / /var/www/FlaskApp/app.wsgi
<Directory /var/www/FlaskApp/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Это полная трассировка стека ошибок
OpenCV Error: Unknown error code -10 (Raw image encoder error: Empty JPEG
image (DNL not supported)) in throwOnEror, file /build/opencv-U1UwfN/opencv-
2.4.9.1+dfsg1/modules/highgui/src/gr
fmt_base.cpp, line 131
[Mon Feb 18 22:30:55.103395 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] mod_wsgi (pid=20626):
Exception occurred processing WSGI script '/var/ww
w/FlaskApp/app.wsgi'.
[Mon Feb 18 22:30:55.103624 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] Traceback (most recent call
last):
[Mon Feb 18 22:30:55.103739 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] File
"/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 703, in
__next__
[Mon Feb 18 22:30:55.105221 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] return self._next()
[Mon Feb 18 22:30:55.105371 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] File
"/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 81,
in _iter_encoded
[Mon Feb 18 22:30:55.107921 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] for item in iterable:
[Mon Feb 18 22:30:55.108077 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] File
"/var/www/FlaskApp/flaskapp.py", line 27, in gen
[Mon Feb 18 22:30:55.108442 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] frame =
camera.get_frame()
[Mon Feb 18 22:30:55.108526 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] File "
"/var/www/FlaskApp/camera.py", line 29, in get_frame
[Mon Feb 18 22:30:55.108747 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] ret, jpeg =
cv2.imencode('.jpg', image)
[Mon Feb 18 22:30:55.108868 2019] [wsgi:error] [pid 20626] [client
2a04:4540:470c:9700:3cc7:709c:1408:230b:62003] error: /build/opencv-
U1UwfN/opencv-2.4.9.1+dfsg1/modules/highgui/src/grf
mt_base.cpp:131: error: (-10) Raw image encoder error: Empty JPEG image (DNL
not
supported) in function throwOnEror