Friday, April 20, 2012

Ok, just set up Ubuntu 11.10, so far so good. VIM kept spitting out A, C, B characters when operating the arrow keys in insert mode. Strangely enough that was cured by copying /etc/vim/vimrc to $HOME/username/.vimrc. Other than that Unity kind of sucks but mostly because it is buggy. I don't know what all the hullabaloo regarding Unity is about, I rather liked it as a desktop environment once I had tweaked it into shape, but as I said it still needs a bit of work.

Wednesday, April 4, 2012

RHEL 6.0 network configuration.

When one selects the default minimal desktop installation RHEL 6.0 does not configure the ethernet interface. To get it working edit the file: /etc/sysconfig/network-scripts/ifcfg-eth0 and set NM_CONTROLLED="no". This ensures the device is no longer slaved to the network manager. Then restart networking:

sudo service network restart

and finally get DNS working by editing: /etc/resolv.conf

search **yourdomain**
nameserver **address**
nameserver **address**

It's a workaround but it got my box connected.

Thursday, January 19, 2012

I ♥ MacBook Air

I just bought a MacBook Air (Model 4,2) and IT ROCKS!!! This is largely thanks to the SSD but the 50% weight reduction from my old MacBook also helps. Boot time is drastically shorter and Photoshop files hundreds of megabytes in size load in mere seconds. My disk space has just been cut in half to 250 Gb but I'm not complaining. The product of the last 10 years of amateur photography will just have to be farmed out to a USB disk (or a 'vagrant' as we call it up here in the arctic) and I'll find a way to live with USB 2.0 until I can afford a Tunderbolt ™ drive. Of course if history is anything to go by, and given my recent strain of catastrophically bad luck, Apple will announce a new MBA with USB 3 ports and a Retina Display tomorrow. Incidentally the Apple Genius who sold it to me my new MBA was wrong, you can upgrade the SSD in the model 4,1 and 4.2 MacBook Airs.

Arrrrgh!

The iPhone audio problem is back. The only thing that seems to help is to reboot the phone which works for a while until, once again, 'phasmatis in machina'. This seems to be a software problem so the only thing to do is wait for iOS 5.1 and hope the apple-farmers got around to fixing this bug.

Wednesday, January 4, 2012

iPhone 4S audio source problem

Had some trouble with my iPhone which refused to allow me to change the audio source while a phone call was in progress. Symptoms, with a Bluetooth headset connected:

  1. Trying to change the audio source during a phone call causes the audio to be lost.
  2. For some reason the default audio source was stuck on 'Speaker' whenever a call came in.

To fix this go to Settings->General->Accessibility->Physical & Motor->'Incoming calls' (not exactly the first place anybody would think look for this setting) and change the audio source from 'Default' to 'Headset'. This causes the phone to select the Bluetooth headset as default if it is connected, otherwise the call will default to the phone and switching to speaker works reliably.

Thursday, July 14, 2011

Eigenfaces with OpenCV 2

Time to try and make this blog live up to it's domain name. I recently started playing around with face recognition. It seems there are fairly few Open Source libraries for face recognition. What I found after some searching online was:
  • libface, Uses OpenCV's Eigenfaces.
  • The Colorado State University FR Algorithm Evaluation suite. It includes some source code and provides the following algorithms: 
    • Eigenfaces.
    • Eigenfaces with Linear Discriminant Analysis.
    • Bayesian Intrapersonal/Extrapersonal Classifier.
    • Elastic Bunch Graph Matching.
  • OpenCV, provides Eigenfaces.

Since I knew nothing about face recognition I began my quest by reading a pile of CS papers* and (inevitably) settled on starting with "Eigenfaces" which is the simplest of the holistic face recognition methods. There are several tutorials on how to implement Eigenfaces with OpenCV but most of the ones I found use the C AP and not the improved C++ API. On top of that the the C++ API was redesigned which means older tutorials that used the C API cannot always be quickly rewritten.

Some years ago Servo Magazine  published a fine series of OpenCV articles (made available online by cognotics.com). The series included two installments on Eigenfaces. The first installment did a good job of explaining Eigenfaces and Principal Component Analysis.  The second installment presented a simple implementation. I set myself the goal of rewriting this code in the new OpenCV C++ API and testing it. I recommend reading the introductory part of the Servo Magazine article and the Eigenfaces paper by Turk & Pentland, "Eigenfaces for Recognition" before proceeding. The paper is quite well written and relatively easy to understand.

* The face-rec.org site has a papers list that is a good place to start.

Eigenfaces in the OpenCV C++ API
In the OpenCV C++ API Eigenfaces is packaged into the PCA object  which in turn is neatly tucked away under array operations. This class can be used to easily implement Eigenfaces and is simpler to use than the old C API:
  • PCA(const Mat& data, const Mat& mean, int flags, int maxComponents=0);
    • data - The set of training faces (Γ = {Γ1, Γ2 ... ΓM}).
    • mean - You can provide a pre-calculated average face (Ψ) of the set of training faces (Γ) or an empty matrix in which case the average face is calculated from the set of training faces you provided.
    • components - How many principal components to retain.
  • Mat project(const Mat& vec) const;
    • Projects a face vector into face-space: (ωk=ukT(Γ-Ψ)).
  • Mat eigenvectors;
    • The eigenfaces (ω) which are the training faces (Γ) after projection into face-space.
  • Mat eigenvalues;
    • The eigenvectors (u) used to project faces to and from face-space.
  • Mat mean;
    • The average face (Ψ) .
The code
I wrote a simple program (not my cleanest code ever) that does more or less the same as the test program in the Servo Magazie tutorial did and it uses the same Cambridge University Computer Lab face database (preview here). The program was written for and compiled on a MacBook so Windows and Linux users may have to do a little tweaking of the includes and the makefile before the code compiles. The test program has several options:

   eigenfacetest [-vs] [-t training image list] [-r test images list]
      -v: Verbose mode.
      -s: The projected face vectors can be retrieved and rendered
          as images. This option shows the average face and a 
          few of the eigenfaces.
      -r: A list of test files with faces to try and recognize.
      -t: A List of training files with faces for the recognizer.

    It expects two files: train_original.txt and test_original.txt which are the files that came with the original Servo Magazine article but you can specify your own test and training file sets with the -t and -r options.

    The average face on the left and three eigenfaces.

    A little experiment
    Running the test sets from the original article gave me an encouraging 100% recognition rate which was way too good to be true. I decided to run the program on the entire set of test images using the first image for each individual as the training image and the rest as test images. The experiment was then repeated with two training images and eight test images etc.

    Train/Test1/92/83/74/6
    Correct66.4%75.6%78.6%85%

    The results were not quite as good as they were using the original Servo Magazine test-sets but rather consistent with what I thought they would be after reading all those CS papers i.e, that he accuracy would be between 60 and 70%. The accuracy goes up as the size of the training set increases. The accuracy with only one training image per subject is what one would expect from a simple Eigenfaces implementation and the fact that the Cambridge University face database, although small, contains a fair number of non frontal faces. The CU data set is, however, well lit and one would expect that variations in lighting conditions would cause the recognition rate to go down. To improve the results one might try further automatic preprocessing with eye detection, rotation and scaling.


    Downloads
    • The source code, it's makefile and the test set lists can be downloaded here
    • You'll have to download the face database your self, here.

    Wednesday, March 23, 2011

    Infinity blade

    I bought yet another iPhone game, Infinity Blade. It's a 3rd person over-the-shoulder type game but it's not like the ones I usually buy where you have complete freedom of movement. Infinity blade is more like Doom Resurrection, you have limited control over where you want to move except at decision points where you can choose to take one of several routes. The plot is simple, you navigate your way through a castle, dueling a string of monsters on the way until, you reach the throne room of the immortal god-king. Once you get past his champion the dark knight, you get a single crack at killing the boss him self. If you fail you have to start over from the beginning. As you progress through the game you gather money, and experience. The money you can spend on better weapons and armor, the XP points you can spend on better defensive, offensive or magic skills. As you gather XP your skill level increases but since XP points are gathered by "mastering" weapons you are under constant pressure to upgrade your arsenal since your skill level will advance slowly or not at all if you are using a set of mastered armor, shield, sword etc. At certain points in the game, usually before or after duels you can pan to the sides to look around which is important to remember since bonus items are often placed out of sight.

    The game it self has amazingly nice graphics for a mobile game, it should do since it uses the Unreal engine. The movements of the characters are also very well done and convincing. Like all of these 3D games it will burn through your iPhone's battery with blistering speed. All in all, IMHO, it's good value at € 4.99 since it's a game that's reasonably hard to master and in a sense goes on infinitely. So, thumbs up!


    A fire paladin,  his frozen buddy,  an assassin...

    they have feral trolls,  knights,  robots...

    a big ugly baby,  the dark knight and once you get past him...

    you finally get to duel with the boss, who kicks your ass many times forcing you to start over, until you finally manage to kill him.

    You don't get to keep the infinity blade, then you press a button and a hologram appears but only after you watch the credits. After all this the game starts all over again. At least you get to keep your XP and your weapons.