pythonopencvhikvision

error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'VideoCapture'


I am trying to enable the IP cam that I have access to, it's feed by the browser. but couldn't able to get a video stream using an IP camera, only get a result in image form. The feed with cv2.videocapture() gives an error.

import cv2
import requests
import numpy as np
from hikvisionapi import Client

cam = Client('http://*.*.*.*', '****', '******', timeout=10)

vid = cam.Streaming.channels[102].picture(method ='get', type = 'opaque_data')


cap = cv2.VideoCapture(vid)

# Check if the webcam is opened correctly
if not cap.isOpened():
 raise IOError("Cannot open webcam")

while True:
  ret, frame = cap.read()
  frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
  cv2.imshow('Input', frame)

  c = cv2.waitKey(1)
  if c == 27:
    break

  cap.release()
  cv2.destroyAllWindows()

Solution

  • by using the below code the error is resolved

    ret, frame = cap.read()
    #print('About to show frame of Video.')
    cv2.imshow("Capturing for facial recog",frame)