我需要有关程序的帮助。我的目标是在带有引导程序的网络服务器烧瓶中与IP摄像机一起流式传输,我想出了如何做到这一点,并且也使Web界面像输入框和按钮一样...但是问题是当我在其中写入IP摄像机的IP地址时输入框中出现此错误:
ValueError:视图函数未返回响应
看起来它没有将ip文件中的ip地址返回给python文件中的函数。
在这里我想尝试一下...
html文件:
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Live Streaming</h1>
</div>
<ul class="list-group">
<li class="list-group-item">Stream with IP Camera: <span><a href="#" class="btn btn-sm btn-primary" id="IPcambtn">Start</a></span>
</li>
</ul>
<div id="IPcam" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="IPcamlbl" aria-hidden="true">
<div class="vertical-alignment-helper">
<div class="modal-dialog modal-sm vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="IPcambl">Enter camera's IP address:</h4>
</div>
<div class="modal-body">
<form action="{{url_for('stream')}}" role="form" id="IPcam" method="post">
<input type="hidden" name="formType" value="IPcam">
<div class="form-group">
<label for="basic-url">IP Address:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon3">rtsp://</span>
</div>
<input name="IPaddress" type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" style="width: 275px;>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs- col-xs-offset- text-center">
<!-- Do NOT use name="submit" or id="submit" for the Submit button -->
<button type="submit" class="btn btn-danger" tabindex="3">Confirm</button>
<div class="panel-body">
<img id="pic" src="{{ url_for('IPstream') }}" class="img-responsive img-rounded"></img>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
python文件:
class Stream(flask.views.MethodView):
@login_required
def get(self):
return flask.render_template('stream.html')
def post(self):
formType = flask.request.form.get('formType')
IPcamPass = ""
if formType == "IPcam":
required = ['IPaddress']
for r in required:
IPcamPass += flask.request.form.get(r)
print ("Connecting with IP Camera...")
database().writeLogs("IP Camera connection established")
flask.flash("You are now connected with IP Camera")
IPstream()
#Functions for IP Camera streaming.
@app.route('/IPstream')
def IPstream():
return Response(IPcam(),mimetype='multipart/x-mixed-replace; boundary=frame')
return ""
def IPcam():
camera = cv2.VideoCapture(IPaddress)
while True:
success, frame = camera.read() # read the camera frame
if not success:
break
else:
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
错误:
Traceback (most recent call last)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/middleware/proxy_fix.py", line 228, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1615, in full_dispatch_request
return self.finalize_request(rv)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1630, in finalize_request
response = self.make_response(rv)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1725, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response