error: (-5:Bad argument) CAP_IMAGES: can‘t find starting number (in the name of file): rtsp://admin

想看一下opencv读取rtsp码流并存图的时间消耗,代码如下:

import time
import cv2

cap = cv2.VideoCapture(" rtsp://admin:xxxx2021@116.xxx.90.xxx:554/h264/ch1/main/av_stream")
ret,frame = cap.read()
for i in range(10):
    start_time = time.time()
    cv2.imwrite("./img/temp.jpeg", frame)
    end_time = time.time()
    print("process time is :", end_time - start_time)

结果发现报错:
OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file): rtsp://admin:xxxx2021@116.xxx.90.xxx:554/h264/
之前经常用,并没有出现过,查了一些解决方案,没效果,最后发现问题在

cap = cv2.VideoCapture(" rtsp://admin:xxxx2021@116.xxx.90.xxx:554/h264/ch1/main/av_stream")

双引号中的rtsp地址前不能有空格,如下

cap = cv2.VideoCapture("rtsp://admin:xxxx2021@116.xxx.90.xxx:554/h264/ch1/main/av_stream")

问题解决。
附带bmp,jpg和png格式存图的时间消耗做参考

save jpg time is : 0.04970407485961914
save png time is : 0.11170268058776855
save bmp time is : 0.00502777099609375
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值