mmcv 对比 cv2 处理视频速度

import os
import time
source = './11/2021-4-13-10-41-51.mp4'
# 将视频转成图片序列后的分辨率
new_width = 224
new_height = 224


import mmcv
s = time.time()
# 读取视频
video = mmcv.VideoReader(source)
if video is None :
    print('Warning: unable to open video source: ', source)
lll = len(video)
for i in range(lll):
    if video[i] is not None:

        # 改变图片分辨率
        if new_width>0 and new_height>0:
            out_img = mmcv.imresize(video[i], (new_width,new_height))
        else:
            out_img = video[i]
        mmcv.imwrite(out_img, os.path.join('out_dir','img_%05d.jpg'%i))
    else:
        warnings.warn(
            'Length inconsistent!'
            f'Early stop with {i + 1} out of {len(vr)} frames.')
        break
e = time.time()
print(e-s)          # 2.1249728202819824     2.2611641883850098     2.648266315460205        2.231487512588501



import cv2
s = time.time()
# opencv版本的视频转图像序列
cap = cv2.VideoCapture(source)
if cap is None or not cap.isOpened():
    print('Warning: unable to open video source: ', source)
i = 0
while True:
    ret, img = cap.read()
    if ret == False:
        break
    if img is not None:
        # 改变图片分辨率
        if new_width>0 and new_height>0:
            out_img = cv2.resize(img, (new_width,new_height))
        else:
            out_img = img
        cv2.imwrite(os.path.join('out_dir','img_%05d.jpg'%i), out_img)
    else:
        warnings.warn(
            'Length inconsistent!'
            f'Early stop with {i + 1} out of {len(vr)} frames.')
        break
    i += 1
e = time.time()
print(e-s)              # 1.9834942817687988        2.1920833587646484          2.027904987335205       2.0143558979034424

 

热运行多次(这里只记录了4次),综合来开,cv2速度是更快的,大约平均快 0.3s +

环境:windows10、EditPlus5.0、python3.7.6、mmcv1.3.1、open-cv4.4.0.46

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值