Augmented World Expo (AWE) '13

I recently got the opportunity to attend AWE ‘13 to demonstrate ARPool and give a talk. The conference was very cool, it was awesome to interact with people working on similar ideas and get inspired by their successes. I even got to try out Google Glass!

I am particularly excited about the “How To” applications of Augmented Reality, like one of the keynotes said we’re not quite at the matrix learn to fly this helicopter level but we are moving towards that direction.

ARPool was really popular and I had a great time sharing it with everyone, we also got a lot of nice press coverage - hopefully this helps us find a commercial partner!

ABC News: http://abclocal.go.com/kgo/video?id=9127769&pid=null

AWE.tv Demonstration http://youtu.be/iLCVVVAA1vw

AWE.tv Interview http://youtu.be/BaA3Wr4yxIc

AWE Talk http://youtu.be/Nf3cQfhUx-A

USA Today http://www.usatoday.com/story/tech/personal/2013/06/05/augmented-reality-expo-google-glass/2392769/

PCWorld http://www.pcworld.com/article/2040801/google-glass-competitors-vie-for-attention-as-industry-grows.html

PC Advisor http://www.pcadvisor.co.uk/news/mobile-phone/3452063/yes-theres-a-trade-show-for-augmented-reality-and-its-demos-are-enchanting/

ARPool::getInstance() Refactor

Finally got a chance to blog about the most recent architectural improvements to ARPool - Singletons! Singletons make so much sense for ARPool it’s insane, I can’t believe we didn’t have it like this before.

Backing up for those who aren’t familiar with what I’m talking about, a singleton is an object for which we enforce the constraint that there will only ever be a single instance of that object. How do we do this? easy make the constructor private, err okay but then how do we instantiate the singleton in the first place? This one isn’t hard but I wouldn’t say easy, we make a public method called getInstance which returns a pointer to the single instance of the class if it has already been initialized or creates it if it has not. The class also has 2 static variables to hold the single instance and a flag indicating whether it has been instantiated yet. The code looks like this:

// header
class Singleton

  private:
  static bool instanceFlag;
  static Singleton* single;

  public:
  Singleton* getInstance();

  // the rest of the methods...

};

// cpp file
bool Singleton::instanceFlag = false;
Singleton* Singleton::single = NULL;

Singleton* Singleton::getInstance()
{
  if(!instanceFlag)
  {
    single = new Singleton();
    instanceFlag = true;
    return single;
  }
  else
  {
    return single;
  }
}

So why would we want to do this? when is this useful? The best example is whenever you are dealing with hardware or an actual physical element. For example in ARPool there is only one camera so it makes sense to make the camera class a singleton.

The major advantage of using singletons is that you can include the class where ever you like and simply ask for the instance - this can greatly simplify your code because you no longer have to pass all of these objects to each other to access them. A really basic way to think about Singletons is to treat them as safe global objects.

and thats really all there is to it! I’m just going to sit here and smile thinking about how much cleaner ARPool’s code is now mmmmmmmmmmmmm!

A Note on porting MATLAB to Python/NumPy

As I am getting into some of the more mathy parts of my thesis I’ve ended up doing a lot of work porting MATLAB code to python and I wanted to share my experience and wisdom for others who might try this as well.

First of all why am I doing this? Well I prefer working with open tools and as a friend of mine recently pointed out if you are using proprietary software to “prove” something it can’t really be called valid because you can’t confirm what the software is really doing. A good point indeed. Now I know there is Octave (which if you are a MATLAB user I highly recommend you check out it’s 99.9% compatible and of course totally free and open source) which I’ve used quite a bit, in fact that’s what I was using to run the MATLAB code while porting. But I prefer having my code in python because I find MATLAB code harder to read and the architecture of code in MATLAB just isn’t quite to my liking. Also it’s much handier to have everything in python for when I bring the application back to computer vision because I’ll have OpenCV to work with. And finally as a personal preference I also like working with my “samples as rows” in my data matrices  probably because of the computer vision I do.

So if you’re like me and you’re porting MATLAB to NumPy and you’ve found your way here then lets review the basic task at hand. We’re actually after 3 main goals here and it’s worth pausing and considering them separately:

1) Port from MATLAB to NumPy

2) Switch from “by cols” mentality to “by rows” mentality

3) Clean up the architecture and probably restructure as a class

Step 1 - Having done this a few times the first thing I recommend is this: write the code line for line the same only using NumPy, yeah I know you want to get in there and make it nicely formatted as a class or other but trust me do a one to one conversion first and leave it as “by cols”.  You can use def myFunc(*args) in python to mimic MATLAB’s nargin functionality. There is a great document on the NumPy website that highlights the main differences and what to use where, notably how NumPy handles by element operations and dot products is different so read up! I should also mention that for step 1 (we’re leaving it as by col for now) if you are doing any reshaping of the data using built-in functions NumPy defaults to row major while MATLAB uses column major. You can force NumPy to prioritize columns in reshape by using the “F” option in either flatten or reshape.

Afterwards you’ll want to test your output to make sure it gives the same result. If you end by having to work backwards and determine where the python code deviates numerically here are a few simple things that can help:


Python/NumPy MATLAB/Octave
savetxt('data.csv',X,delimiter=',') csvwrite('data.csv',X)
X=loadtxt('data.csv',delimiter=',') X=csvread('data.csv')
print X disp(X)
raw_input() pause()

Also work with the same input! That should be obvious. Then work your way through using print statements, saving data out and waiting for user input if required. NumPy and MATLAB print slightly differently but it is pretty easy to compare across. (I used to have a formatted print statement for one of them that matched the other but I lost it damn, shouldn’t be too tough to redo if you need it though, there also may be something online already I never checked).

Step 2 - switch from “by cols” to “by rows” now by this I mean that in a data matrix containing samples MATLAB users tend to think of each column as a sample while other people tend to thing of each row as a sample. It’s really just a different way of arranging the data but it can be tricky to revert. When you are switching col to row paradigm you’ll need to switch some of the equations around - get out a pen and paper and write out a simple case of the math for both row wise and col wise and check it through. It took me a very long time to find a simple ordering bug that resulted in a square matrix rather than a scalar. gah!

Step 3 - Now finally go nuts and format it nicely! make it a class encapsulate it whatever floats your boat! I’ve also found that a lot of MATLAB code was clearly written to test if something works and thus when you actually go to use it it’s quite awkward so I’ve found the usability goes up a lot with python.

And that’s it I hope this helps someone out there. I mainly just really wanted to write this up because I just successfully finished a tricky port and was really stoked about it. I’ve got one more to do so maybe I’ll refine this post a bit shortly!

tl;dr NumPy »> MATLAB