Introduction
This guide will walk you step by step through using a Linux or Mac based device to access an RTSP (Real Time Streaming Protocol) stream of a webcam connected to the same local network as your computer and run a simple python script to begin capturing and storing images from the live RTSP feed. Perfect for creating a machine learning data set or gathering images for later analysis!
-
-
An RTSP compatible webcam
-
A Computer that has access to Linux command line utilities (usually a device with MacOS or a Linux/unix operating system)
-
The computer must also have Python 3. As well, as the the openCV Python library installed. Links to instructions to install each are embedded.
-
A Network Switch
-
2x Ethernet cables (Cat 5 or higher)
-
-
-
In order to Connect to the RTSP stream of our camera to establish a live feed we first need to find the IP address (a unique address that identifies a device on a local network) of our camera
-
To find the IP address we first need to determine the network protocol being used on your server switch.
-
To do this first connect just your linux based terminal and camera to the switch via Ethernet and make not of your cameras MAC address
-
This will be found on the camera or in the documentation accompanying it.
-
-
-
Now open the linux terminal on your computer and run the command ifconfig in the terminal this should bring up a list of network protocols along with information that accompanies them
-
Now look at the ether heading under each protocol and find the MAC address that corresponds your camera. The protocol that has your camera in the ether will be your network protocol!
-
Next type the following command into your linux terminal: sudo arp-scan --interface=<your_network_interface> --localnet
-
Note: Replace <your_network_interface> with the name of the network interface that you are using to connect to the switch (e.g., eth0, wlan0, enp3s0, etc.).
-
after the common has finished running look for the entry that corresponds to your webcam. The entry will typically include the manufacturer's name or a model number. The IP address of your webcam will be listed in the first column of the entry.
-
-
-
Congratulations you have found your IP address the hardest part of finding your Camera's RTSP URL.
-
Your camera's specific RTSP URL will depend on the manufacturer of the camera however the formatting for the RTSP URL for nearly every manufacturer can be found here
-
The link above will provide specific instructions for your camera based on manufacturer a couple tips that apply across the board however are that the Port field of the stream format will typically be 554 and any usernames or passwords can either be found on your camera or in its documentation unless otherwise changed.
-
You can test your RTSP URL to make sure it is correct and running properly by opening your computers VLC media player going to the media tab going to the open network stream button and typing in your RTSP URL
-
-
-
Now that you have your RTSP Stream URL working it is time to use your simply copy the code I wrote here
-
To run the code first specify the how often you would like the code to collect an image, the file path of the directory you would like the images saved to, the RTSP URL and, the number of images you want to collect!
-
The coded has the added ability to display the RTSP feed while images are being collected as well as the functionality to timestamp the images if the timestamp is added in brackets to the fstring that is the image file names
-
Now run your code from the terminal and collect data! Perfect for generating data from a machine learning model or sending data to some sort of image analysis tool!
-
Cancel: I did not complete this guide.
One other person completed this guide.