hyansuper / picam-video-streaming

Stream PiCamera mjpeg video to web using Flask and cv2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PiCamera Video Streaming

This is derived from flask-video-streaming by @miguelgrinberg.

I made some changes to support dynamic PiCamera configuration and simple API for stream receiving:

  1. run app.py on raspberry pi
  2. visit http://pi-address:5000 to view video stream, you can also specify resolution/framerate/hflip/vflip in the url, eg. http://pi-address:5000/?w=640&h=480&fps=10&hf=1&vf=1
  3. to receive video stream from another computer, run receive.py or use:
  • RemotePiCamera(pi_address, resolution=(320,240), framerate=10, hflip=False, vflip=False)
  • ThreadedRemotePiCamera(pi_address, resolution=(320,240), framerate=10, hflip=False, vflip=False)
from remote_pi_camera import RemotePiCamera
import cv2
for frame in RemotePiCamera(pi_address):
    cv2.imshow('picam', frame)
    if cv2.waitKey(1) ==27: # if user hit esc
        break
cv2.destroyAllWindows()

The threaded version has a background thread to receive video stream, which behaves more similar to cv2.VideoCapture. If the client read()s from the stream slower than the server writes to the stream, unprocessed frames will jam in RemotePiCamera, while ThreadedRemotePiCamera will only read() the newest frame and discard old frames. They are both not thread-safe.

Ref

About

Stream PiCamera mjpeg video to web using Flask and cv2

License:MIT License


Languages

Language:Python 96.0%Language:HTML 4.0%