我很难找到使用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
发布于 2012-01-28 12:28:25
import numpy as np
import cv2
def rotate_image(image, angle):
image_center = tuple(np.array(image.shape[1::-1]) / 2)
rot_mat = cv2.getRotationMatrix2D(image_center, angle, 1.0)
result = cv2.warpAffine(image, rot_mat, image.shape[1::-1], flags=cv2.INTER_LINEAR)
return result
假设您使用的是cv2版本,该代码会找到您想要旋转的图像的中心,计算转换矩阵并应用于该图像。
发布于 2013-09-08 20:18:10
发布于 2015-10-04 10:00:34
def rotate(image, angle, center = None, scale = 1.0):
(h, w) = image.shape[:2]
if center is None:
center = (w / 2, h / 2)
# Perform the rotation
M = cv2.getRotationMatrix2D(center, angle, scale)
rotated = cv2.warpAffine(image, M, (w, h))
return rotated
https://stackoverflow.com/questions/9041681
复制相似问题