error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'VideoCapture'
error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'VideoCapture'
我正在尝试启用我有权访问的 IP 摄像头,它由浏览器提供。但无法使用 IP 摄像机获取视频流,只能以图像形式获取结果。带有 cv2.videocapture() 的提要给出错误。
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()
通过使用以下代码解决了错误
ret, frame = cap.read()
#print('About to show frame of Video.')
cv2.imshow("Capturing for facial recog",frame)
我正在尝试启用我有权访问的 IP 摄像头,它由浏览器提供。但无法使用 IP 摄像机获取视频流,只能以图像形式获取结果。带有 cv2.videocapture() 的提要给出错误。
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()
通过使用以下代码解决了错误
ret, frame = cap.read()
#print('About to show frame of Video.')
cv2.imshow("Capturing for facial recog",frame)