Tutorial

Table Of Contents
93
18 OpenCV Learn to Use OpenCV
The real-time video transmission function comes from the open source project of Github the MIT open
source agreement flask-video-streaming.
First, prepare two .py files in the same folder in the Raspberry Pi. The code is as follows:
·app.py
#!/usr/bin/env python3
from importlib import import_module
import os
from flask import Flask, render_template, Response
from camera_opencv import Camera
app = Flask(__name__)
def gen(camera):
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('/')
def video_feed():
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', threaded=True)
·base_camera.py
import time
import threading
try:
from greenlet import getcurrent as get_ident
except ImportError:
try: