使用 python 连接到 Hikvision Camera 并打开 cv
Connecting to Hikvision Camera using python and open cv
我想将 Hikvision 网络摄像机与 python 连接并使用此代码打开 cv:
import numpy as np
import cv2
cap = cv2.VideoCapture()
cap.open("rtsp://yourusername:yourpassword@172.16.30.248:555/Streaming/channels/2/")
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',ret)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
当我 运行 我的代码出现这个错误时:
Traceback (most recent call last):
File "C:\Users\Amin\Desktop\ip camera in py\csm.py", line 15, in <module>
cv2.imshow('frame',ret)
cv2.error: OpenCV(4.0.0) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:261: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper<struct cv::Set<1,-1,-1>,struct cv::Set<3,4,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F)
我用 VLCPlayer 测试了我的相机,它运行完美!
我认为问题与opencv4有关!
我该如何解决? tnx 很多
错误是您在 OpenCV 的 imshow()
函数中传递 BOOLEAN
值而不是 Mat
值:
cv2.imshow('frame',ret)
所以你应该通过框架:
cv2.imshow('frame',frame)
cap.read()
in Python
returns 两个值,一个是Boolean
表示帧是否读取成功,第二个是帧本身.所以你应该检查 ret
如果它是 true
,然后显示框架。
我想将 Hikvision 网络摄像机与 python 连接并使用此代码打开 cv:
import numpy as np
import cv2
cap = cv2.VideoCapture()
cap.open("rtsp://yourusername:yourpassword@172.16.30.248:555/Streaming/channels/2/")
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',ret)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
当我 运行 我的代码出现这个错误时:
Traceback (most recent call last):
File "C:\Users\Amin\Desktop\ip camera in py\csm.py", line 15, in <module>
cv2.imshow('frame',ret)
cv2.error: OpenCV(4.0.0) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:261: error: (-2:Unspecified error) in function '__cdecl cv::CvtHelper<struct cv::Set<1,-1,-1>,struct cv::Set<3,4,-1>,struct cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F)
我用 VLCPlayer 测试了我的相机,它运行完美!
我认为问题与opencv4有关!
我该如何解决? tnx 很多
错误是您在 OpenCV 的 imshow()
函数中传递 BOOLEAN
值而不是 Mat
值:
cv2.imshow('frame',ret)
所以你应该通过框架:
cv2.imshow('frame',frame)
cap.read()
in Python
returns 两个值,一个是Boolean
表示帧是否读取成功,第二个是帧本身.所以你应该检查 ret
如果它是 true
,然后显示框架。