Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.53 KB

README.md

File metadata and controls

58 lines (39 loc) · 1.53 KB

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://admin:instar@192.168.1.19: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://admin:instar@192.168.2.117/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