Error when connecting an IP camera to Opencv (-215:Assertion failed)

Asked

Viewed 135 times

0

Good afternoon, guys! What’s up? So, I’m trying to connect a webcam per ip to the open cv, the webcam would be the camera on my phone and I’m using the Droid cam for that. It happens that I always come across this mistake:

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 my 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

1 answer

0


If you can access your camera by placing the ip in the browser, try:

import cv2

ip = "http://xxxx/?action=stream"  #colocar o ip da camera
cam = cv2.VideoCapture(ip)

_, img = cam.read()

cv2.imshow('frame', img)
cv2.waitKey(0)      

Browser other questions tagged

You are not signed in. Login or sign up in order to post.