def shearImage(image_array, shear_value):
rows, cols, ch = image_array.shape
pts1 = np.float32([[5, 5], [20, 5], [5, 20]])
pt1 = 5 + shear_value * np.random.uniform() - shear_value / 2
pt2 = 20 + shear_value * np.random.uniform() - shear_value / 2
pts2 = np.float32([[pt1, 5], [pt2, pt1], [5, pt2]])
shear_matrix = cv2.getAffineTransform(pts1, pts2)
shear_image = cv2.warpAffine(image_array, shear_matrix, (cols, rows))
return shear_image
评论列表
文章目录