MonoTouch Virtual ‘Try On’ App for Eyewear

February 5, 2013

Here’s a prototype I’ve been working on using MonoTouch and EmguCV

EmguCV is a a cross platform .Net wrapper to the OpenCV image processing library. Obviously this lends itself to the world of Mono and Android / iOS – brilliant!

Although you can download and test this wrapper in MonoDevelop via the iOS simulator, some of the library I was interested in needed the ‘device’ build. And for that you need to buy a licence.

I eagerly paid the money and started a’codin.

The main requirement of the app was to use facial/eye/nose recognition and place a scaled pair of glasses on your face. FYI there are many apps in the App Store that do this using a variety of techniques, but I don’t like many of them and most don’t lend themselves to being used by commercial eyewear companies. I guess what I am saying is that there needs to be a trade off between what looks absolutely awesome (3D augmented reality) and what is practical when it comes to constantly changing product lines. Economics trumps technology.

My approach is just to place a 2D image over your eyes. Lets face it (pun intended), once you get an idea of what the frames will look like on, you’ll want to try them ‘in store’ to get the real 3D experience. I really think this idea suites the new online eyewear paradigm of ordering glasses to try at home first before buying, all for the cost of delivery. Using an app to find & then order the ones you think look virtually good first, makes sense to me. An example of a company using ‘home try on’ in Australia is Sneaking Duck, while in the U.S another I’ve seen is Warby Parker.

IMG_0653 IMG_0656 IMG_0659

My prototype is using a combination of sensing techniques to help achieve the results above.

  • Accelerometer to sense camera stability
  • Image motion detection to sense picture stability
  • Gamma correction to enhance image
  • Haar Cascade algorithms for face/eyes/nose detection

I had lots of fun making this prototype. I am looking to collaborate, so let me know if you are an eyewear company and want to use this in some way. Cheers!


Using CryptAcquireContext ASP.NET Web Service

November 16, 2011

Hey. I’ve been signing Google URLs via a Windows Service and everything been fine, thanks for asking.

To sign a Google API URLs (e.g. Google Directions API) you need a signing key and also a crypto library to use a HMAC – specifically HMACSHA1. So P/Invoking the Windows cryptographic API through .NET is fine until you need to do it through an ASP.NET Web Service. Anyway, I have seen many people trying to get this working without success and I thought I’d share my answer.

The main issue is when you call to “CryptAcquireContext”. If the calling user doesn’t have access, this method with return “File Not Found”, or something similar.

Simply make sure your web service runs in it’s own App Pool, and then change the Identity that the App Pool runs under.

In IIS7, right click the App Pool, Advanced Settings, In the list -> Process Model ->Identity. I changed this to “Local Service” and everything work fine after that. You can use “Network Service” but then this gives the process network access permissions.

Here is link on IIS7 and App Pool identities,

A ‘cool’ ORM goes Mono

October 29, 2010

I have recently started using this simple & elegant ORM called CoolStorage, written by the people from The Vici Project.

What makes CoolStorage great is that it’s been tweaked for MonoTouch and SQLite. All you need to do to start using it is,

  • download the assemblies that have been build for Mono on the Mac
  • reference them in you MonoTouch projects
  • add a few lines of startup/connection code

Once you’ve pointed CoolStorage at your SQLite database, the last piece of the puzzle is (well you may have guessed, as this is an ORM) to create some C# classes that map to you table structure. What I love is the lack of attribute annotation that you need, here is an example,

public class Cups : Vici.CoolStorage.CSObject<Cups, int>
public int ID { get { return (int)GetField(“ID”); } }

// This one maps automatically
public string Type { get { return (string)GetField(“Type”); } set { SetField(“Type”,value); } }

public string Desc { get { return (string)GetField(“Desc”); } set { SetField(“Desc”,value); } }

public int Size { get { return (int)GetField(“Size”); } set { SetField(“Size”,value); } }

Now when you want to create and save a new cup,

Cups newCup = Cups.New();
newCup.Type = “Glass”;
newCup.Desc = “A cup for juice”;
newCup.Size = 250; // ml

Anyway you get the idea. There is much more to learn so make sure you head over to their website!

Last thing to mention. The Novell team have been working feverishly on getting Mono on the Android platform; I’m sure you’ve heard by now about MonoDroid. Well I’ve by messing around with it in its Beta form on Windows/Visual Studio 2010. Since SQLite is the database of choice for this platform, I figured that I would try to get CoolStorage work there too.

It’s not too difficult as it turns out, here are the steps,

  • I created two MonoDroid library projects in VS 2010, one for vici.core.dll & one for vici.coolstorage.dll
  • Downloaded the code for vici.core & vici.coolstorage, see The Vici Project website
  • Added the current source code into the respective projects.
  • Removed the database drivers that come standard in vici.coolstorage, like Access & SQL Server
  • Added the database driver for SQLlite on MonoTouch (CSConfig.cs & CSDataProviderSQLite.cs)
  • Included an assembly reference to the Mono.Data.Sqlite DLL
  • Included a compilation symbol (MONOTOUCH) to both projects
  • Build & you’re done!

Now you can include these MonoDroid assembly versions of CoolStorage into your MonoDroid apps.

There is only one Gotcha! Took me a while to figure it out, but you need to make sure that your MonoDroid app is targeting 2.2 of the Android OS. It seems that previous versions of SQLite on Android didn’t support many of the needed functionality.

Anyway enjoy!

Var, MonoTouch & SDK4.0

August 3, 2010

Since upgrading to iPhone SDK4.0 I have seen a difference in MonoTouch using the ‘var’ type, when used in nested event handlers.

For example in the code below, I get a crash when I hit the OK button. This never happened in the previous MonoTouch|iPhoneSDK incarnations.

public partial class FlipsideViewController : UIViewController {
 public override void ViewDidLoad () {
  base.ViewDidLoad ();
  var right = new UIBarButtonItem("Hello", UIBarButtonItemStyle.Bordered, null);
  right.Clicked += HandleButtonRightClicked;
  _navigationItem.RightBarButtonItem = right;

 void HandleButtonRightClicked (object sender, EventArgs e) {
  var alert = new UIAlertView("Message","This is a message",null, "OK", null);
  alert.Dismissed += delegate { };

Obviously this is how you can fix it,
private UIAlertView alert = null;
void HandleButtonRightClicked (object sender, EventArgs e) { alert = new UIAlertView("Message","This is a message",null, "OK", null); alert.Dismissed += delegate { }; alert.Show(); }
BTW, the exception related an unhandled exception "unrecognized selector sent to instance".

SQLite & Dates

June 17, 2010

I said it before and I’ll say it again, I really like SQLite’s approach to data types. Especially storing dates as strings on the way in, and then using functions for query and comparison on the way out. Anyway that’s it.

Sqlite database crash

May 18, 2010

Recently I set up a SQLite database for an iPhone application using this great little browser.

Reading from the database was fine (using System.Data.Sqlite.Dll is a breeze), but every time I tried to write to the database it was crashing the app. After much debuging & un/commenting of code I finally remembered that the directory of the main application bundle is read-only, and that is where I had the database! Thus on first run after installation, I now copy the blank database to the “Documents” directory and use it from there.

It was a silly mistake but I hope this helps others, because the MonoTouch framework was not throwing an exception, and when the app just crashes on you it’s difficult to determine what’s going wrong.

Objective-C, my new best friend

April 9, 2010

If Apple have their way (and why wouldn’t they) then it looks like all of us MonoTouch developers better dust off the old Obj-C reference manuals. It seems in the new iPhone developer program agreement (OS 4.0) we must only use the following languages to build apps; Obj-C/C/C++ and JavaScript.

Check this out for more info. What a shame. Disappointed.

An IoC that follows you around

March 31, 2010

I want to briefly mention this fantastic IoC container. It is small & easy to use. Best of all it is suited to the world of mobility – small footprint and quick setup.

I intent to use this container in my iPhone apps with MonoTouch, but have already used it at work on the Windows Mobile platform. It really came to the rescue while refactoring the DA layer of our application allowing us to point to multiple mobile databases without any fuss. Just needs a little configuration file for setup purposes.

Look here for details:

Fare Estimator

March 24, 2010

Recently was working on a POC for work using MonoTouch. Taxi Fare Estimator. Calling web services to calculate fare cost and using the Core Location & UIMapkit, it ended up being a nice little funky app. It provides for address search and map display, user favourites and address alternatives (if more than one match found).

Anyway while developing, a local taxi company launched the same type of app, which also allowed for bookings. Never mind.

WCF Data Services

March 24, 2010

Creating an iPhone app at the moment with MonoTouch. Sorry can’t give away any details, but using WCF Data Services (AKA ADO.NET Data Services) to populate my UITableViewControllers. Very cool and light. Thank god the mono team included System.Json.dll in their roadmap, as it makes it a breeze to extract the incoming data.