WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Sunday, January 15, 2012

Micro Frameworks - Http - ORM

Not sure if you guys are keeping track of non-Microsoft based programming like node.js, but the new trend seems to be event driven programming. In .net world it's basically asynchronous programming. There were two articles that I came across recently, one was asynchronous wcf & other being asynchronous asp.net mvc

There has been a lot of buzz around http micro-frameworks in .NET world namely OWIN (Open web interface in .NET). First came Kayak [http://kayakhttp.com] and then came Nancy [https://github.com/thecodejunkie/Nancy], Nina [http://jondot.github.com/nina], ManosDeMono [http://manosdemono.org] and many more [http://owin.org/#projects]. All of these basically is one or more variation of Sinatra [ruby - http://www.sinatrarb.com]. Nina seems to be pretty cool, as they have support for different View Engines (Spark, django, Razor,haml). KayakHttp is a standalone server making it independent of IIS. My experience with Kayak has been quite pleasantful but you do need to remember it’s a event driven programming model.

But like http micro-frameworks there are quite a buzz around micro-ORM too. Frameworks like Dapper.NET [http://code.google.com/p/dapper-dot-net] and Simple.Data [https://github.com/markrendle/Simple.Data] are gaining a lot of traction. Simple.Data is quite a framework for it’s ability of plugin interface.

Labels: ,

Face.com human readable Data

Face.com is without any doubt one of the best Face detection API out there. Considering the fact that Face.com provides 5000 request per hour is quite a good API access for a small or personal project. But unfortunately not all Data provided by face.com is human readable. Following is an example of face.com api result



All the data that face.com provides is a percentage relation with the height and width of the image. This is very advantageous since even if we resize the image, the percentage of the face on the image would remain excatly the same and the same place on the image. Offcourse while resizing the image, the aspect ratio must be maintained. Besides the coordinates of eye, mouth and nose there are other values like size of head (width, hight) and yaw, roll and pitch. Lets say you are building an application to identify if the person in the face is facing the camera or to check if the image is a potrait image or a full body shot, face.com doesn’t provide these information as words but rather as numbers. Following is a translation of the obove numbers into more human readable words:

For determining the angle of the face:



For determining if the image is a portrait image:



Note: above calculations are based on my opinion of the image based on trail and error.

Other attributes that Face.com provides (more human readable) are as follows:

Labels:

Face.com Post image - Local File - Face Detect

Face.com has two ways of accessing it’s API. One way is a simple Http GET, for example:

http://api.face.com/faces/detect.json?api_key={YOURAPIKEY}&api_secret={YOURSECRETKEY}&urls=http://farm3.static.flickr.com/2566/3896283279_0209be7a67.jpg

and the second way is to use Http POST to url [http://api.face.com/faces/detect.json]. In the GET request, you have to provide the URL of the image and in the POST request you can post image from your local machine. Unfortunately the examples on Face.com is quite vague. The example that they provided is like the following:

Content-Type: multipart/form-data; boundary=nonRelevantString
Content-Length: 104687
-----------------------------nonRelevantString
Content-Disposition: form-data; name="api_key"
4b4b4c6d54c37
-----------------------------nonRelevantString
Content-Disposition: form-data; name="api_secret"
sfhs8fj948fj29
-----------------------------nonRelevantString
Content-Disposition: form-data; filename="image.jpg"
Content-Type: image/jpeg
<>


Looking at the above example, it provides no information on how the post parameters should be constructed. Some of the examples that I came across was building the above text and post this as part of request header like the following example:

http://developers.face.com/forums/post2315.html#p2315

Bummer!

The basic idea of Face.com POST request is to post a multipart form with fields like “api_key”, “api_Secret” and “filename”. Following is a much cleaner code to post an image to face.com for face detection.



that “fileToUpload” is a input of type “File” like the following:



For those who are not aware of FormData, it’s a HTML5 element to build form object.

Labels: ,