I'm fairly sure there would be a mathematical approach to it, matching the selected vertices on the model with the corresponding positions on the picture as was done in that example. As to what that mathematical approach would be, I have no idea.

Ok, some Google research led me from
"camera matching" http://www.complete-support.com/stat...val+Guide.html
to "photogrammetry" http://en.wikipedia.org/wiki/Photogrammetry
to "Levenberg-Marquardt algorithm" http://en.wikipedia.org/wiki/Levenbe...ardt_algorithm
of which there is an implementation in C at https://sourceforge.net/projects/lmfit/

Hope that helps.