我很难找到使用OpenCV在Python语言中将图像围绕特定点旋转特定角度(通常非常小)的示例。
这就是我到目前为止所得到的,但它产生了一个非常奇怪的结果图像,但它有些旋转:
def rotateImage( image, angle ):
if image != None:
dst_image = cv.CloneImage( image )
rotate_around = (0,0)
transl = cv.CreateMat(2, 3, cv.CV_32FC1 )
matrix = cv.GetRotationMatrix2D( rotate_around, angle, 1.0, transl )
cv.GetQuadrangleSubPix( image, dst_image, transl )
cv.GetRectSubPix( dst_image, image, rotate_around )
return dst_image
发布于 2013-09-02 13:08:55
快速调整到@alex-rodrigues的答案...处理形状,包括通道的数量。
import cv2
import numpy as np
def rotateImage(image, angle):
center=tuple(np.array(image.shape[0:2])/2)
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
return cv2.warpAffine(image, rot_mat, image.shape[0:2],flags=cv2.INTER_LINEAR)
https://stackoverflow.com/questions/9041681
复制相似问题