python 简单图像处理(4) 旋转
旋转有一个绕什么转的问题。我们先来看最简单的,绕第一个像素转,则旋转的情况会像这样:
令旋转前有
旋转a角度后有
以矩阵形式表示为
编写程序:
import cv
import math
def SRotate(image,angle):
size = (image.width,image.height)
iSRotate = cv.CreateImage(size,image.depth,image.nChannels)
for i in range(image.height):
for j in range(image.width):
anglePi = angle*math.pi/180.0
x = int(math.cos(anglePi)*i+math.sin(anglePi)*j)
y = int(-math.sin(anglePi)*i+math.cos(anglePi)*j)
if x>-1 and x-1 and y-1 and x-1 and y-1 and x-1 and y
页:
[1]