Ask Your Question

Revision history [back]

Python: src.empty() when i try to use rtsp link instead a normal camera

Hi i'm trying to execute this simple code to test a rtsp link instead a normal camera but it doesnt work

the code is:

import numpy as np
import cv2


#cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture("rtsp://admin:[email protected]:554/h.264/ch1/main/av_stream")

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',frame)
    cv2.imshow('gray',gray)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

i tested the rtsp link is ok because i tested in vlc media player, but i think the error comes from how the code extracts the data from the link.

The camera is an EZVIZ model CS-CV248, this is a IP camera.

The full error is:

"error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor"