I'm trying to get some code that will perform a perspective transformation (in this case a 3d rotation) on an image.
import os.path import numpy as np import cv def rotation(angle, axis): return np.eye(3) + np.sin(angle) * skew(axis) \ + (1 - np.cos(angle)) * skew(axis).dot(skew(axis)) def skew(vec): return np.array([[0, -vec[2], vec[1]], [vec[2], 0, -vec[0]], [-vec[1], vec[0], 0]]) def rotate_image(imgname_in, angle, axis, imgname_out=None): if imgname_out is None: base, ext = os.path.splitext(imgname_in) imgname_out = base + '-out' + ext img_in = cv.LoadImage(imgname_in) img_size = cv.GetSize(img_in) img_out = cv.CreateImage(img_size, img_in.depth, img_in.nChannels) transform = rotation(angle, axis) cv.WarpPerspective(img_in, img_out, cv.fromarray(transform)) cv.SaveImage(imgname_out, img_out) When I rotate about the z-axis, everything works as expected, but rotating around the x or y axis seems completely off. I need to rotate by angles as small as pi/200 before I start getting results that seem at all reasonable. Any idea what could be wrong?
