我想将海康威视ip摄像机与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()
当我运行我的代码时,我遇到了这个错误:
^{pr2}$我用VLCPlayer测试了我的相机,它工作得很好!在
我想问题出在opencv4!在
我怎样才能修好它?tnx很多
错误是在OpenCV的
imshow()
函数中传递BOOLEAN
值,而不是Mat
值:所以你应该传递帧:
^{pr2}$cap.read()
中的cap.read()
返回两个值,一个是Boolean
,它显示帧是否被成功读取,第二个值是帧本身。所以您应该检查ret
如果它是true
,然后显示框架。在相关问题 更多 >
编程相关推荐