python


Camera rotation matrix


I am trying to raytrace a video. For that matter, I need the camera roation matrix for every frame, in world coordinates. The camera is at the origin. There are no translation.
I have the trajectory of the camera as changes in rotation for every frame.
So for every frame, I have three values (roll, yaw, pitch) that describe how much the camera should rotate from this frame to the next. These rotations are to be understand in the camera coordinate system.
How do I compute the world coordinate rotation matrices for the frames?
What I tried:
def rot_x(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
def rot_y(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
def rot_z(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
matrices = [initial_rot]
for pitch, yaw, roll in frames_data:
rx = rot_x(pitch)
ry = rot_y(yaw)
rz = rot_z(roll)
last_matrix = matrices[-1]
matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
(Since last_matrix should be orthonormal, so the inverse of it should be the transpose).
However, something is horribly wrong, the rendered video just flickers in the y dimension. I am sure there is something wrong with the math here..
The order of the matrix multiplications matters. Applying another rotation should be done by left-multiplying (assuming a standard convention).
Since this is simply composition multiple rotations, there should not be any need to inverse the last rotation.
The complete rotation that should be computed for frame N is:
R_n = R(yaw_n, pitch_n, roll_n) R_{n - 1} R_{n - 2} ... R_1 R_0
with:
R_0: the initial rotation (i.e. initial_rot)
R_n: the complete rotation for the frame N
R(yaw_n, pitch_n, roll_n): the rotation derived from the yaw / pitch / roll values applied between frame N - 1 and N (i.e. rx.dot(ry).dot(rz))
Hence the last line in the code excerpt should instead be:
rotation = rx.dot(ry).dot(rz)
matrices.append(rotation.dot(last_matrix))

Related Links

How to use a tensorflow model extracted from a trained keras model
How to query with many tables
python-shell on linux system indentation error
How come 1 is printed instead of 0?
How to subtracting two hyperspectral image?
Getting an error: list assignment index out of range
Launching dev_appserver.py from windows powershell gives me “too few arguments” error
How do you split all of a certain character in Python [duplicate]
Issues with data types in pandas functions
Firebase Console but there is error tell “Error Generating Download URL”
Python Twitter Streaming Timeline
Interval intersection in pandas
Putting double quotes for an output string
How to query with raw SQL using Session or engine
getUser return EDAMSystemException errorCode=8
How to print the subject of a single email using uid

Categories

HOME
symfony
sass
tinyos
rotation
uibutton
wxwidgets
label
qpython3
avl-tree
ipfs
vuex
eclipse-cdt
iso
abcpdf
postmessage
netezza
yeoman-generator
ng2-dragula
sensu
katharsis
spring-data-neo4j
google-api-dotnet-client
gzip
forum
superagent
ivy
vegan
protobuf-net
android-vpn-service
freebase
division
rhino
windows-10-iot-core
pox
pace
es-shell
code-behind
fltk
visualstudio.testtools
google-account
scalafx
automator
web-deployment-project
seamless-immutable
udev
decompress
etherpad
chessboard.js
multifile-uploader
jackson-databind
listadapter
django-south
concur
inet
amazon-kcl
usb-drive
group-concat
handlebars.java
file-diffs
geodjango
insert-into
application-loader
selendroid
textkit
rx-groovy
debian-based
rspec3
pgm
robocode
pl-i
picat
late-static-binding
uipickerviewcontroller
nscolor
leptonica
html-form-post
localtime
surveyor-gem
pascals-triangle
template-haskell
android-contextmenu
vt100
file-exists
entity-framework-ctp5
flash-cs5.5
nsindexpath
django-nose
gtk2hs
cookieless
port-scanning
junit3
ruby-debug
audiostreamer
exitstatus
google-instant
revision

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App