[Python] Why won’t OpenCV’s VideoCapture open my RTSP stream, and how can I fix it?

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    Can anyone tell if this IP camera is capable of streaming in OpenCV. I tried this but still not working. I think the problem is to find the correct URL, I'm hoping you could find some solution on this problem.

    Rover System: MODEL - RND-813HBKSCD IP dome camera

    This sample code from python 2.7/3 works fine in my laptop camera but when I try my IP camera it doesn't respond to it.

    import cv2
    import numpy as np

    faceDetect=cv2.CascadeClassifier('C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml');
    cam=cv2.VideoCapture(0);

    while(True):
    ret,img=cam.read();
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces=faceDetect.detectMultiScale(gray,1.3,5);
    for(x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
    cv2.imshow("Face", img);
    if(cv2.waitKey(1)==ord('q')):
    break;
    cam.release()
    cv2.destroyAllWindows


    when I use this sample IP camera URL:


    It's get this.


    error: Traceback (most recent call last): File "C:\Users\Romel II G. Albia\Surveillance_IPC\IPCNB\Snap\192.168.1.13\stream1.py", line 17, in main() File "C:\Users\Romel II G. Albia\Surveillance_IPC\IPCNB\Snap\192.168.1.13\stream1.py", line 9, in main cv2.imshow('frame', frame) error: C:\build\master_winpack-bindings-win32-vc14-static\opencv\modules\highgui\src\window.cpp:331: error: (-215) size.width>0 && size.height>0 in function cv::imshow
    ​

    Continue reading...

Compartilhe esta Página