Vision¶
+This module provides an interface for grabbing an rtmp stream and using the images to do some processing in opencv.
+How do I use this module?
+-
+
Get frames from the raspberry pi camera
+– here comes your own processing –
+Publish the processed frames on an http server
+You can view the http stream of your processed images in a web browser
+
Opencv Stream¶
+Because of the rtmp stream needing to buffer some frames and waiting for P-Frames, importing this module might take up +to 5 Seconds.
+-
+
-
+class
compLib.Vision.
__Streaming
¶
+ Class that handles rtmp streaming for opencv.
+DO NOT CREATE AN INSTANCE OF THIS CLASS YOURSELF!
+This is automatically done when importing this module. Use Vision.Streaming which is +an instance of this class!
+grab frames -> do your own processing -> publish frame -> view on http server
+-
+
-
+
get_frame
()¶
+ Grab the newest frame from the rtmp stream.
+-
+
- Returns +
An opencv frame
+
+
-
+
-
+
publish_frame
(image)¶
+ Publish an opencv frame to the http webserver.
+-
+
- Parameters +
image – Opencv frame that will be published
+
+- Returns +
None
+
+
-
+
Examples¶
+Using the Vision Module¶
+import cv2
+from compLib import Vision
+
+# get newest opencv frame from camera
+frame = Vision.Streaming.get_frame()
+
+# do some processing with the frame.....
+
+# publish frame to streaming server
+Vision.Streaming.publish_frame(frame)
+
Connect the raspberry pi to your internet and view the stream at: “http://your_raspi_ip:9898/”. This should display +your raspberry pi camera. Note: the stream will lag a little bit BUT the processing of the image will be done in +realtime.
+The output on the website should show whatever your raspberry pi cam records:
+
Chessboard Detection¶
+In this example we process the captured stream of images and want to detect chessboards. Run this example and +point your raspberry pi camera to a chessboard and it should be detected.
+For testing you can point it at this image:
+
import cv2
+from compLib import Vision
+
+# get newest opencv frame from camera
+frame = Vision.Streaming.get_frame()
+
+criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
+
+# convert image to grayscale image
+gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
+
+# find the chessboard corners
+ret, corners = cv2.findChessboardCorners(gray, (6, 9), None)
+
+# draw detected chessboard position onto the image
+cv2.drawChessboardCorners(frame, (6, 9), corners, ret)
+
+# publish frame to streaming server
+Vision.Streaming.publish_frame(frame)
+
Connect the raspberry pi to your internet and view the stream at: “http://your_raspi_ip:9898/”.
+The output image should look like this:
+
Here is a screenshot of the stream website while viewing the chessboard in this documentation.
+