| #!/usr/bin/env python |
| from importlib import import_module |
| import os |
| from flask import Flask, render_template, Response |
| from argparse import ArgumentParser, SUPPRESS |
| |
| # import camera driver |
| if os.environ.get('CAMERA'): |
| Camera = import_module('camera_' + os.environ['CAMERA']).Camera |
| else: |
| #from camera import Camera |
| from person_detection import Camera |
| |
| # Raspberry Pi camera module (requires picamera package) |
| # from camera_pi import Camera |
| |
| app = Flask(__name__) |
| |
| |
| @app.route('/') |
| def index(): |
| """Video streaming home page.""" |
| return render_template('index.html') |
| |
| |
| def gen(camera): |
| """Video streaming generator function.""" |
| print("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') |
| |
| |
| @app.route('/video_feed') |
| def video_feed(): |
| """Video streaming route. Put this in the src attribute of an img tag.""" |
| print("video_feed()", args) |
| camera = Camera(args) |
| print("Camera: ", camera) |
| return Response(gen(camera), |
| mimetype='multipart/x-mixed-replace; boundary=frame') |
| |
| def build_argparser(): |
| parser = ArgumentParser(add_help=False) |
| args = parser.add_argument_group('Options') |
| args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.') |
| args.add_argument("-m", "--model", help="Required. Path to an .xml file with a trained model.", |
| required=True, type=str) |
| args.add_argument("-i", "--input", |
| help="Required. Path to video file or image. 'cam' for capturing video stream from camera", |
| required=True, type=str) |
| args.add_argument("-l", "--cpu_extension", |
| help="Optional. Required for CPU custom layers. Absolute path to a shared library with the " |
| "kernels implementations.", type=str, default=None) |
| args.add_argument("-pp", "--plugin_dir", help="Optional. Path to a plugin folder", type=str, default=None) |
| args.add_argument("-d", "--device", |
| help="Optional. Specify the target device to infer on; CPU, GPU, FPGA, HDDL or MYRIAD is " |
| "acceptable. The demo will look for a suitable plugin for device specified. " |
| "Default value is CPU", default="CPU", type=str) |
| args.add_argument("--labels", help="Optional. Path to labels mapping file", default=None, type=str) |
| args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering", |
| default=0.5, type=float) |
| args.add_argument("-ns", help='No show output', action='store_true') |
| |
| return parser |
| |
| if __name__ == '__main__': |
| args = build_argparser().parse_args() |
| app.run(host='0.0.0.0', threaded=True) |