Ask Your Question

Revision history [back]

I can't connect ip camera to opencv (-215:Assertion failed)

Hi, there! How are you? Well, I'm using my cell phone as a camera with droidcam and i'm trying to connect a ip camera into opencv, but I'm reciving this message error everytime I try:

Traceback (most recent call last):
  File "c:/Users/uriel/Documents/Python/Project #1/droidcam.py", line 10, in <module>
    cv2.imshow('IPWebcam',img)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

Here's the full code:

import urllib.request
import cv2
import numpy as np
import time
URL = "http://xxx.xxx.x.xxx:xxxx/"
while True:
    img_arr = np.array(bytearray(urllib.request.urlopen(URL).read()),dtype=np.uint8)
    img = cv2.imdecode(img_arr,-1)
    #imS = cv2.resize(img,(960, 540))
    cv2.imshow('IPWebcam',img)

    if cv2.waitKey(0):
        break

Details:

Python Version: 3.8.2 OpenCv Version: 4.2.0 OS: Windows 10 64bits