Reputation: 63
I'm using a raspberry pi and trying to create a video stream using flask and the pi camera library. My understanding is that I need to use continuous_capture to get the lowest latency within the system.
However, I can't find a way to preview these images that are supposedly being taken. Is there a way I can view these before I try and implement it into flask which has many issues itself as I will be using the falsk website to control a robot as well.
Any suggestions on how to do this are appreciated as well as telling me there is an easier way to do it. Please note I am only an intermediate programmer so nothing too complex for me to understand as this is the whole idea of the project.
Upvotes: 0
Views: 6812
Reputation: 160
I believe you are looking for capture_continuous
.
Here's the general process:
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
Upvotes: 3