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

Is there an effective way to hide an inline keyboard with python telegram bot?
Overriding django current app in a django template
Python script to query google maps and get the resulting URL [closed]
the difference between multiprocessing.sharedctypes.Value and multiprocessing.Value in python
TensorFlow placeholder dimension - what's the difference?
Python “scraping” maps/images
Python terminal output width
SQLAlchemy metadata column type with Postgresql interval hour to second
how to delete excel rows using python
Handling streaming data that gets saved in a file in python
Parsing XML column in SQL Alchemy results
Result wasn't printing, why is `print` ignored after `return`?
PySpark to MySQL Insert Error?
How to auto check dynamic data json and post it
IndexError: list index out of range - Odoo v8 to Odoo v10 community
Appending a Linklist Node to a queue

Categories

HOME
sql-server-2008
converter
shopify
xamarin.android
rotation
voip
wsdl
agile
flyway
checksum
rebol
xtext
ext.net
desktop
diagram
xlsx
uiscrollview
future
lstm
zoomcharts
aptana
eclipselink
multicore
jni
sonarqube-msbuild-runner
statusbar
google-ima
k2
visual-c++-2017
chrome-native-messaging
nesc
positioning
xor
apache-cloudstack
picturebox
skygear
body-parser
shibboleth
nodeclipse
fax
mediawiki-extensions
excel-interop
filepath
startapp
w3-total-cache
nstouchbar
ruby-on-rails-2
info
static-code-analysis
jszip
visual-studio-templates
laravel-query-builder
barcode-printing
keycode
build-process
sql-import-wizard
typhoon
iostat
nssplitview
achievements
spinlock
except
jenkins-scriptler
app.xaml
ytplayerview
criteria-api
web-component-tester
ember-cli-addons
es2015
power-law
dache
gfs
facebook-sdk-3.1
gridworld
windows-update
lame
google-closure-library
zend-lucene
blockingqueue
makefile-project
querystringparameter
ou
symbol-server
svn-hooks
asp.net-routing
pci-bus
savestate
usability-testing
virtualquery

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