PiCamera Flask, start and stop preview
我正在 Flask 中创建一个小的 Web 界面,以使用 PiCamera python 模块控制 Raspberry Pi 相机。我有一个显示来自相机的流的工作索引页面。但是,当我通过输入按钮发布 stop_preview() 时,应用程序失败,我无法弄清楚我做错了什么。到目前为止,这是我的一些代码。
这是我的观点的一部分。py
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from flask import redirect, url_for, session, request, // render_template, Response from simplepam import authenticate from app.camera_pi import Camera from app import app @app.route(‘/’, methods=[‘GET’, ‘POST’]) def gen(camera): @app.route(‘/video_feed’) |
这是我的 index.html 模板。
1
2 3 4 5 6 7 8 9 10 11 12 13 |
<!DOCTYPE html>
<html> |
这是 camera_pi.py 文件(取自 Miguel Grinberg 的 github 存储库 https://github.com/miguelgrinberg/flask-video-streaming)
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# The MIT License (MIT) # # Copyright (c) 2014 Miguel Grinberg # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the"Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import time class Camera(object): def initialize(self): # wait until frames start to be available def get_frame(self): def StopPreview(): @classmethod # let camera warm up stream = io.BytesIO() # reset stream for next frame # if there hasn’t been any clients asking for frames in |
我添加了”def StopPreview()”部分,当我从索引页面发布提交按钮时,它被调用,但此时应用程序崩溃了。
提前感谢您提供的任何帮助。
首先,picamera的
要停止摄像头,您必须让方法
例如,您可以向对象添加一个
希望这会有所帮助!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/267890.html