在CV2中旋转图像 Python速度比较

问题描述 投票:0回答:1

我使用了2种不同的方法来旋转图像,从这个 疑问. 在不知不觉中,我已经浪费了一个星期的时间,试图找出为什么我的keras发生器慢了这么多,所以我想我会分享。

我尝试的第一个图像旋转,是相当缓慢的。

import time
t0 = time.time()
img1= ndimage.rotate(img1, 210)
t1 = time.time()

total1 = t1-t0
print(total1)

然后我试了这个旋转。

def rotate(img, angle):
    row, col, channel = img.shape
    rotation_point = (row / 2, col / 2)
    rotation_matrix = cv2.getRotationMatrix2D(rotation_point, angle, 1)
    rotated_img = cv2.warpAffine(img, rotation_matrix, (col, row))
    return rotated_img 

t0 = time.time()
img1 = rotate(img1, 210)
t1 = time.time()

total2 = t1-t0
print('def: ', str(total2))
print(total2/total1)
python tensorflow keras cv2
1个回答
0
投票

当我运行第二种旋转图像的方法时,它给我带来了14倍的加速,这为我节省了很多时间,希望也能帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.