def rotate_image(img_src, angle,scale ):
img_src,size_dest= pad_image(img_src,scale)
size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))
org_h=size[1]
org_w=size[0]
src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)
org_angle =np.arctan(float(org_h)/org_w)
dest_h = size_dest[0]
dest_w = size_dest[1]
center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))
dsize= (dest_w,dest_h)
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)
img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)
x,y,w,h = cv2.boundingRect(img_rot[:,:,3])
return img_rot[y:y+h, x:x+w,:]
评论列表
文章目录