From dd85b28036147375577552ab69fc8ce695fa9abc Mon Sep 17 00:00:00 2001 From: minchulmando Date: Tue, 12 May 2015 09:53:20 +0900 Subject: [PATCH] 2015.05.12 Example and debugging --- ImRotLibrary.py | 8 +++--- Main_ImRotLibrary_Test.py | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Main_ImRotLibrary_Test.py diff --git a/ImRotLibrary.py b/ImRotLibrary.py index 6d25730..6562c38 100644 --- a/ImRotLibrary.py +++ b/ImRotLibrary.py @@ -10,14 +10,14 @@ #-------------------------------------------------------------------------------- # import the basic librarires -from math import atan2, cos, sin, sqrt +from math import atan2, cos, sin, sqrt, pi from numpy import float64, hypot, zeros, flatnonzero, array # Makes 3D rotation matrices from axis/angle def Fn_AxisAngle2RotMat(matrix, axis, angle): # Trig factors. - ca = cos(angle) - sa = sin(angle) + ca = cos(pi*angle/180) + sa = sin(pi*angle/180) C = 1 - ca # Depack the axis. @@ -84,7 +84,7 @@ def Fn_RotMat2AxisAngle(matrix): # Angle. r = hypot(axis[0], hypot(axis[1], axis[2])) t = matrix[0,0] + matrix[1,1] + matrix[2,2] - theta = atan2(r, t-1) + theta = 180*atan2(r, t-1)/pi # Normalise the axis. axis = axis / r diff --git a/Main_ImRotLibrary_Test.py b/Main_ImRotLibrary_Test.py new file mode 100644 index 0000000..81ec7bb --- /dev/null +++ b/Main_ImRotLibrary_Test.py @@ -0,0 +1,55 @@ +#-------------------------------------------------------------------------------- +# Image transformation and filtering functions of Computer Vision class (2015-1) +# +# Minchul Lee: Initial code generation (2015.05.07) +# Minchul Lee: Debug (2015.05.12) +#-------------------------------------------------------------------------------- + +# Import libraries +import numpy as np +import ImRotLibrary as IMRot + +#------------------------------------------------------------------------ +# Axis, angle to Rotation matrix representation example +print '\n1) Axis, angle to Rotation matrix representation example' +angle = 90.0 # degree +axis = np.float64(np.array([1,0,0])) # axis +RotMat = np.zeros((3,3)) # zero matrix initializaition +print 'Angle: ', angle, ' [deg], Axis: ', axis + + +# functino run +IMRot.Fn_AxisAngle2RotMat(RotMat, axis, angle) + +print 'Rotation matrix:\n', RotMat +#------------------------------------------------------------------------ + +#------------------------------------------------------------------------ +# Rotation matrix to Axis, angle representation example +print '\n2) Rotation matrix to Axis, angle representation example' +print '[Info] Upeer rotation matrix is used for this exmaple\n' +#function run +axis_RotMat, angle_RotMat = IMRot.Fn_RotMat2AxisAngle(RotMat) + +print 'Axis:', axis_RotMat, ', Angle: ', angle_RotMat, '[deg]' +#------------------------------------------------------------------------ + +#------------------------------------------------------------------------ +# quaternian to Rotation matrix representation example +print '\n3) quaternian to Rotation matrix representation example' +Quat = np.float64(np.array([np.sqrt(2)/2, 0, 0, -np.sqrt(2)/2])) +print 'Quaternion: ', Quat +RotMat_Quat = np.zeros((3,3)) + +IMRot.Fn_Quat2RotMat(Quat,RotMat_Quat) +print 'Rotation matrix:\n', RotMat_Quat +#------------------------------------------------------------------------ + +#------------------------------------------------------------------------ +# Rotation matrix to quaternian representation example +print '\n4) Rotation matrix to quaternian representation example' +print '[Info] Upeer rotation matrix is used for this exmaple\n' + +Quat_RotMat = IMRot.Fn_RotMat2Quat(RotMat) +print 'Quaternion: ', Quat_RotMat +#------------------------------------------------------------------------