在CV2 Python速度比较中旋转图像
我用了两种不同的方法来旋转图像。在不知情的情况下,我花了整整一周的时间试图弄明白为什么我的keras发电机慢了这么多,所以我想我会和大家分享 我试过的第一个图像旋转速度很慢在CV2 Python速度比较中旋转图像,python,tensorflow,keras,cv2,Python,Tensorflow,Keras,Cv2,我用了两种不同的方法来旋转图像。在不知情的情况下,我花了整整一周的时间试图弄明白为什么我的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, channe
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)
当我以第二种方式旋转图像时,它给了我14倍的加速