Tutorial
Table Of Contents
- 1. Premise
- 2. Raspberry Pi System Installation and Developmen
- 3 Log In to The Raspberry Pi and Install The App
- 4 Assembly and Precautions
- 5 Controlling Robot via WEB App
- 6 Common Problems and Solutions(Q&A)
- 7 Set The Program to Start Automatically
- 8 Remote Operation of Raspberry Pi Via MobaXterm
- 9 How to Control WS2812 RGB LED
- 10 How to Control The Servo
- 11 How to Control DC Motor
- 12 Ultrasonic Module
- 13 Line Tracking
- 14 Make A Police Light or Breathing Light
- 15 Real-Time Video Transmission
- 16 Automatic Obstacle Avoidance
- 17 Why OpenCV Uses Multi-threading to Process Vide
- 18 OpenCV Learn to Use OpenCV
- 19 Using OpenCV to Realize Color Recognition and T
- 20 Machine Line Tracking Based on OpenCV
- 21 Create A WiFi Hotspot on The Raspberry Pi
- 22 Install GUI Dependent Item under Window
- 23 How to Use GUI
- 24 Control The WS2812 LED via GUI
- 25 Real-time Video Transmission Based on OpenCV
- 26 Use OpenCV to Process Video Frames on The PC
- 27 Enable UART
- 28 Control Your AWR with An Android Device
- Conclusion
113
25 Real-time Video Transmission Based on
OpenCV
● This chapter introduces real-time video transmission, which can transmit the images collected by the
camera to other places in real time for displaying images or handing it to the host computer for machine vision
processing.
● The software functions of this tutorial are based on opencv, numpy, zmq (read Zero MQ) and base64
libraries. Before writing the code, you need to install these libraries.
pip3 install opencv-contrib-python numpy zmq pybase64
●In this tutorial, the hardware mainly uses a PC and a Raspberry Pi with a camera installed, because it
can introduce the installation methods of related libraries on the Windows platform and Linux platform at the
same time.
●OpenCV is an open source computer vision library. In the Linux system, you can enter in the terminal:
sudo apt-get install -y libopencv-dev python3-opencv
● In the windows system, you can install it by downloading the .whl file of opencv, or you can use the
following command in the terminal to install OpenCV:
pip3 install opencv-contrib-python
●NumPy is a basic software package for scientific calculations using Python. In Linux, install numpy by
typing sudo pip3 install numpy in the terminal.
● In Windows, install numpy by typing pip3 install numpy on the command line (cmd) (need to install
python3.x in advance).
●zmq and base64 are used for frame transmission and frame encoding and decoding respectively in this
project. In linux, enter sudo pip3 install zmq pybase64 to install, and in windows, enter pip3 install zmq
pybase64 to install.
●After installing the relevant libraries, let's explain the program of the video sending end. The RPiCam.py
python program is used to collect the pictures from the camera, and encode the collected pictures to the
receiving end of the video. So we put RPiCam.py into the Raspberry Pi and run it.
●RPiCam.py:
'''
First import the required libraries, the above has a specific introduction to these libraries
'''
import cv2
import zmq
import base64
import picamera
from picamera.array import PiRGBArray
'''
Here we need to fill in the IP address of the video receiver (the IP address of the PC)