Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1.  
  2. main.py
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. from flask import Flask, render_template, Response
  5. from camera import VideoCamera
  6. import time
  7.  
  8. app = Flask(__name__)
  9.  
  10. class MainObject():
  11.         def __init__(self, app):
  12.         self.app = app
  13.         self.Status = True
  14.                 self.share = "Sharing ?"
  15.         @self.app.route('/')
  16.         def hello_world():
  17.             return render_template('index.html')
  18.  
  19.  
  20.         def abc(camera):
  21.             while self.Status == True:
  22.                 self.frame = camera.GetBw()
  23.                 yield (b'--frame\r\n'
  24.                        b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')
  25.  
  26.        
  27.                 def gen(camera):
  28.             while self.Status == True:
  29.                 self.frame = camera.get_frame()
  30.                 yield (b'--frame\r\n'
  31.                        b'Content-Type: image/jpeg\r\n\r\n' + self.frame + b'\r\n\r\n')
  32.        
  33.         @app.route('/video_feed')
  34.         def video_feed():
  35.             return Response(abc(VideoCamera()),
  36.                     mimetype='multipart/x-mixed-replace; boundary=frame')
  37.                        
  38.                 @app.route('/video_feed_proceesed')
  39.         def video_feed_proceesed():
  40.             return Response(gen(VideoCamera()),
  41.                             mimetype='multipart/x-mixed-replace; boundary=frame')
  42.        
  43.         @app.route('/stop' ,methods=['POST'])
  44.         def stop():
  45.             self.Status = False
  46.             return "stoped"
  47.  
  48.         @app.route('/start' ,methods=['POST'])
  49.         def start():
  50.             self.Status = True
  51.             return "Started"
  52.    
  53.  
  54. if __name__ == '__main__':
  55.     mainObject = MainObject(app)
  56.     mainObject.app.run(debug=True,threaded=True)
  57.  
  58.  
  59. index.html
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61.  
  62. <html>
  63.   <head>
  64.       <meta http-equiv="X-UA-Compatible" content="IE=edge">
  65.   <meta name="viewport" content="width=device-width, initial-scale=1">
  66.       <script src="static/js/ajax.js"></script>
  67.       <script src="http://cdn.jsdelivr.net/webshim/1.14.5/polyfiller.js"></script>
  68.       <script type="text/javascript" language="javascript">
  69.     $(document).ready(function() {
  70.         $("#start").click(function(event){
  71.     $.post(
  72.             "/start",
  73.         function(data) {
  74.             window.alert(data);        
  75.             location.reload();
  76.             }
  77.         );     
  78.                 });
  79.         $("#stop").click(function(event){
  80.         $.post(
  81.             "/stop",
  82.         function(data) {
  83.                     window.alert("data");
  84.             }
  85.         );
  86.         });
  87.                
  88.       });
  89.       </script>
  90.     <title>Video Streaming Demonstration</title>
  91.   </head>
  92.   <body>
  93.     <h1>Video Streaming Demonstration</h1>
  94.     <button id ="start" type="button" value = "Load Data">Start</button>
  95.     <button id ="stop" type="button" value = "Load Data">Stop</button>
  96.     <img src="{{ url_for('video_feed') }}">
  97.     <img src="{{ url_for('video_feed_proceesed') }}">
  98.   </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement