欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PIL和cv2读图片速度对比

程序员文章站 2024-01-20 16:51:52
...

使用cornell grasp dataset测试,我之前做实验删过一些,剩下878张图像。

程序

# -*- coding: UTF-8 -*-
"""===============================================
@Author : wangdx
@Date   : 2020/8/5 15:26
==============================================="""

from PIL import Image
import cv2
import numpy as np
import time
import os

path = 'E:/research/dataset/grasp/cornell/wdx/TriangleLabel/label'

file_dirs = []
for file in os.listdir(path):
    file_dirs.append(os.path.join(path, file))

# PIL测试
start_time = time.time()
for file in file_dirs:
    im = np.array(Image.open(file))
pil_time = time.time() - start_time

# cv
start_time = time.time()
for file in file_dirs:
    im = cv2.imread(file)
cv_time = time.time() - start_time

print('image num: ', len(file_dirs))
print('PIL: sum time: {:.5f}'.format(pil_time))
print('cv: sum time: {:.5f}'.format(cv_time))

结果

image num:  878
PIL: sum time: 11.54827
cv: sum time: 4.84759