当前位置:网站首页>【OpenCV】记录cv2.VideoCapture的一个坑
【OpenCV】记录cv2.VideoCapture的一个坑
2022-07-19 13:35:00 【Xavier Jiezou】
项目场景
需要使用cv2.VideoCapture来获取海康摄像机的RTSP流视频。
问题描述
如果RTSP流视频的链接是正确的,那么很好,没有任何问题,访问也很快。如何链接的IP或端口不对,那么延时就非常高:
import cv2
import time
t1 = time.time()
tmp1 = cv2.VideoCapture('rtsp://admin:[email protected]:554')
tmp1.release()
print(time.time()-t1) # 1.36(秒)
t1 = time.time()
tmp2 = cv2.VideoCapture('rtsp://admin:[email protected]:555')
tmp2.release()
print(time.time()-t1) # 32.3(秒)
为了不一直等待下去,我们需要做一个延时判断,给定一个最大响应时间,如果在该时间内程序仍未执行完成,则立即结束。
解决方案
- 安装第三方库 func_timeout
pip install func_timeout
- 按照如下形式改写程序
import cv2
import time
from func_timeout import func_timeout, FunctionTimedOut
t1 = time.time()
tmp1 = cv2.VideoCapture('rtsp://admin:[email protected]:554')
tmp1.release()
print(time.time()-t1) # 1.36(秒)
t1 = time.time()
try:
tmp2 = func_timeout(3, cv2.VideoCapture, ('rtsp://admin:[email protected]:555',))
except FunctionTimedOut:
print('执行超时')
print(time.time()-t1) # 3.07(秒)
引用参考
边栏推荐
- About the performance of different versions of SQLSERVER database
- constructor
- mongodb-探索阶段[通俗易懂]
- php 踩坑 数组访问
- What are the products of Rongyan?
- 【redis入门系列】初识 redis以及redis的安装
- Phase mechanism in UVM
- DS(StackAnQueueBasiApplication)
- 显式动力学子模型法在航空发动机整机瞬态冲击并行计算中的应用
- Do you still have certificates to participate in the open source community?
猜你喜欢
深入了解JUC並發(八)線程池
uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec
Originally, MAE proposed by he Kaiming is still a kind of data enhancement! Based on MAE, Shanghai Communications & Huawei proposes masking reconstruction data enhancement, which is better than cutmix
[depth] the new LAAS agreement elephant: the key to revitalizing the development of the defi track
还不懂MySQL数据库?阿里p8架构师带你深入浅出MySQL与优化
参与开源社区还有证书拿?
Which is the best test management tool?
[matlab project practice] Research on UAV image compression technology based on region of interest
ES6 -- iterator, basic use of generator
MySQL eight part essay, preparing for the golden nine silver ten
随机推荐
【MATLAB项目实战】基于感兴趣区域的无人机图像压缩技术研究
国际原油期货怎么操作开户才安全?
[ERROR] COLLATION ‘utf8_ unicode_ ci‘ is not valid for CHARACTER SET ‘latin1‘
关于不同版本的SQLSERVER数据库性能问题
Open the link in wechat and jump to the follow page of official account
Xcelium xrun user manual
shell编程(十) : [shell基础] 控制脚本
Which is the best test management tool?
浅拷贝和深拷贝的区别?
显式动力学子模型法在航空发动机整机瞬态冲击并行计算中的应用
UVM中set/get_config_int/string/object与uvm_cofig_int/string/object的使用
DS(PatterMatchalgorithm)
【精选】由浅入深带你吃透MQ原理与应用场景
Set/get in UVM_ config_ Int/string/object and UVM_ cofig_ Use of int/string/object
原来何恺明提出的MAE还是一种数据增强!上交&华为基于MAE提出掩蔽重建数据增强,优于CutMix、Cutout和Mixup!...
浅析MySQL中concat及group_concat的使用
C language simulation to realize character function and memory function
Linux 编译安装redis 离线
京津冀综合科技服务平台的建设与思考
Do you still have certificates to participate in the open source community?