Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.py
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- from flask import Flask, render_template, Response
- from camera import VideoCamera
- import time
- app = Flask(__name__)
- class MainObject():
- def __init__(self, app):
- self.app = app
- self.Status = True
- self.share = "Sharing ?"
- @self.app.route('/')
- def hello_world():
- return render_template('index.html')
- def abc(camera):
- while self.Status == True:
- self.frame = camera.GetBw()
- yield (b'--frame\r\n'
- b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')
- def gen(camera):
- while self.Status == True:
- self.frame = camera.get_frame()
- yield (b'--frame\r\n'
- b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')
- @app.route('/video_feed')
- def video_feed():
- return Response(abc(VideoCamera()),
- mimetype='multipart/x-mixed-replace; boundary=frame')
- @app.route('/video_feed_proceesed')
- def video_feed_proceesed():
- return Response(gen(VideoCamera()),
- mimetype='multipart/x-mixed-replace; boundary=frame')
- @app.route('/stop' ,methods=['POST'])
- def stop():
- self.Status = False
- return "stoped"
- @app.route('/start' ,methods=['POST'])
- def start():
- self.Status = True
- return "Started"
- if __name__ == '__main__':
- mainObject = MainObject(app)
- mainObject.app.run(debug=True,threaded=True)
- index.html
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- <html>
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <script src="static/js/ajax.js"></script>
- <script src="http://cdn.jsdelivr.net/webshim/1.14.5/polyfiller.js"></script>
- <script type="text/javascript" language="javascript">
- $(document).ready(function() {
- $("#start").click(function(event){
- $.post(
- "/start",
- function(data) {
- window.alert(data);
- location.reload();
- }
- );
- });
- $("#stop").click(function(event){
- $.post(
- "/stop",
- function(data) {
- window.alert("data");
- }
- );
- });
- });
- </script>
- <title>Video Streaming Demonstration</title>
- </head>
- <body>
- <h1>Video Streaming Demonstration</h1>
- <button id ="start" type="button" value = "Load Data">Start</button>
- <button id ="stop" type="button" value = "Load Data">Stop</button>
- <img src="{{ url_for('video_feed') }}">
- <img src="{{ url_for('video_feed_proceesed') }}">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement