'rotate image by pitch, roll, yaw with python-opencv

I want to rotate an image with given roll, pitch and yaw

Here is the example image

import numpy as np
import math
import cv2

radian = math.radians(30)

def eulerAnglesToRotationMatrix(theta) :
    R_x = np.array([[1,                  0,                   0],
                    [0, math.cos(theta[0]), -math.sin(theta[0])],
                    [0,  math.sin(theta[0]), math.cos(theta[0]) ]])
    R_y = np.array([[math.cos(theta[1]), 0, math.sin(theta[1])],
                    [0,                  1,                  0],
                    [-math.sin(theta[1]), 0, math.cos(theta[1])]])
    R_z = np.array([[math.cos(theta[2]), -math.sin(theta[2]), 0],
                    [math.sin(theta[2]), math.cos(theta[2]),  0],
                    [0,                  0,                   1]])
    R = np.dot(R_z, np.dot( R_y, R_x ))
    return R

R = eulerAnglesToRotationMatrix((0,radian,0))
im = cv2.imread('yaw.png')
im = cv2.warpPerspective(im, R, (im.shape[1], im.shape[0]))
cv2.imshow('win', im)
cv2.waitKey(0)

original image

enter image description here

below is the result rotated by pitch 30 degrees.

enter image description here

the result is wrong.

any idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source