Skip to content

mpolinowski/opencv-rtsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

OpenCV for IP Cameras

Most of the IP cameras supports Real Time Streaming Protocol (RTSP) to control audio and video streaming. This tutorial provides example how to capture RTSP stream from IP camera using OpenCV and Python. OpenCV provides VideoCapture class which allows to capture video from video files, image sequences, webcams, IP cameras, etc. To capture RTSP stream from IP camera we need to specify RTSP URL as argument.

INSTAR IP Cameras

Please use the following URLs to use your INSTAR camera with third-party software:

User and password are your camera login and the default RTSP port is 554 - e.g.:

rtsp:https://admin:[email protected]:554/12

Environment Setup

mkdir ./opencv-rtsp && cd opencv-rtsp
python -m venv .env
source .env/bin/activate
pip install opencv-python

Python Code

import cv2
import os

RTSP_URL = 'rtsp:https://admin:[email protected]/11'

os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'rtsp_transport;udp'

cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)

if not cap.isOpened():
    print('Cannot open RTSP stream')
    exit(-1)

while True:
    success, img = cap.read()
    cv2.imshow('RTSP stream', img)

    if cv2.waitKey(1) & 0xFF == ord('q'):  # Keep running until you press `q`
        break

About

INSTAR IP camera as OpenCV2 Video Source

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages