我正在尝试使用IP网络摄像头应用程序连接手机摄像头,但运行代码时出现错误
而且,URL不断变化。有没有一种方法可以让我不必每次都更改URL
这是我正在使用的代码:
import cv2
cap = cv2.VideoCapture("http://192.168.43.1:8080/shot.jpg")
while True:
ret, frame = cap.read()
cv2.imshow("IPWebcam", cv2.resize(frame, (600, 400)))
if cv2.waitKey(20) & 0xFF == ord('q'):
break
这是我运行它时收到的错误消息:
Traceback (most recent call last):
File ".\phone_cam.py", line 15, in <module>
cv2.imshow("IPWebcam", cv2.resize(frame, (600, 400)))
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-9gpsewph\opencv\modules\imgproc\src\resize.cpp:3929: error:
(-215:Assertion failed) !ssize.empty() in function 'cv::resize'
这个答案不会直接解决问题,但它可以让你检测出原因,在阅读视频、图像或照相机时,这是一个很好的做法。始终检查
ret
的值是否为True
,因为如果不是,则表示读取数据时出现问题如果代码在else语句中打印消息,则表示链接存在问题。检查是否正确,是否需要添加用户名和密码
相关问题 更多 >
编程相关推荐