Python for Computer Vision
Motivation
-
Improved productivity
-
Concise code
-
Good libraries for many purposes
-
Popular with other scientific organisations
-
Willow Garage and ROS
-
Google
-
NASA
-
and more
-
Taught to students
-
More and more students being taught as introduction to programming
-
Transition from Matlab relatively painless
Alternatives
-
C/C++
-
Time consuming for common mathematical operations and structures
-
No interactive shell
-
Edit, compile run cycle slows prototyping development
-
Matlab
-
Licensing
-
Difficulty in deploying on autonomous systems
-
Closed source
-
Matrix legacy
-
Octave
-
No hashtable or set support
-
Buggy 3D visualisation (octaviz)
-
Sage - Open source mathematics software
-
Bundle of programs with python interface
-
Viable alternative to Magma, Maple, Mathematica and Matlab
MROL mapping case study
-
3D mapping algorithm
-
Lines of code (Excluding unit tests)
-
Comparable performance
Basics
-
Getting help - help or following with ?
-
Accessing parts of arrays and matrices
-
arrays versus lists
-
Columns/rows
-
Reverse
Array versus matrix
-
Array - N dimensional array like entity
-
Matrix - Similar to Matlab, mathematical entity
-
Differences
-
Multiplication etc.
-
M = matrix('[1,2]; [3,4]')
-
A = array([[1,2], [3,4])
Python shells
-
Standard, python - Always available
-
ipython - Recommended
-
bpython - Promising
-
Reinteract - Worksheet based
-
Sage
ipython -pylab
-
tab completion
-
help ?
-
hist
-
run versus import
-
pdb
-
using ipython
-
%magic for help on ipython functions
-
Command history
-
.inputrc file
-
set editing-mode vi
-
hist
-
start type and then press up
-
search through commands history
-
ipython qtconsole --pylab
-
ipython notebook
Ipython tips
-
Shortcuts
-
Automatic parentheses
-
pow 2, 3 -> pow(2, 3)
-
Automatic quoting
-
Recursive reload, dreload
-
Shell commands
-
Can be used as a system shell
-
Running code snippets
-
Paste
-
Middle mouse button
-
Run a scratch file
-
Namespace
-
Support for parallel computing
Typical workflow
-
Write a test if possible
-
ipython -pylab
-
Similar to Matlab workflow style
-
Work on small sections of code in interpreter
-
When working incorporate into a text file
-
Run unit test
-
Repeat
Creation and reshaping
-
Creation
-
zeros, ones, eye, diag
-
Sequences - arange versus range
-
shaping
-
reshape
-
a.shape = 3,2
-
a.T
-
flatten
-
Assign all elements
Arithmetical functions
-
roots and logs
-
Rounding
-
Mathematical constants
-
Complex numbers and trig functions
Concatenation and Selection
-
Concatenation
-
hstack, vstack, dstack
-
concatenate((a,a), axis=1)
-
Selecting elements
-
ranges, index lists
a[1:3, :]
a[[1,2], [0,1]]
Gotchas
Linear algebra
a = arange(4).reshape(2,2)
a.T
linalg.det(a)
linalg.inv(a)
norm(a)
lingalg.eig(a)
linalg.svd(a)