Wednesday, June 25, 2008

The musical world of Java

Recently whilst browsing through Geertjan’s blog, to keep myself abreast with the technological happenings of Netbeans; I stumbled upon an interesting write-up which discussed about a Java API for music, namely JFugue. Being inclined to music since my early days, the short write-up immediately caught-up my attention. I didn’t have enough time in hand to investigate it in detail; however, least I had a look at the API’s “programming” guide and was really astonished to find that now one can define musical scores, notes etc. and program an entire virtual orchestra to play and record the same in standard MIDI format.

Following are some more musical Java APIs -

Now that’s definitely music to ears for all the programmers out there who have a musical predilection.

Thursday, June 19, 2008

Rest aside your web services

If you've been thinking of web services and feeling scared of that XML mess in the web service description (wsdl) files. Well, rest aside that scare now. And, by rest I mean, Representational State Transfer (REST).

Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. And thus invariably it could be also implemented in the world of web services as another revolutionary way of communication with web services. In REST, resources have URIs and are manipulated simply through HTTP header operations. Therefore, now one can imagine having a web service without all that WSDL clutter.

REST works around a very simple principle, i.e. HTTP methods POST, GET, PUT and DELETE can be compared with the CREATE, READ, UPDATE, DELETE (CRUD) operations associated with database technologies or any application model objects.

The following table associates several common HTTP verbs with similar database operations, however the meaning of the HTTP verbs do not correspond directly with a single database operation. For example, an HTTP PUT is used to set the value of a resource and may result in either a creation or update as needed.

HTTP CRUD
POST Create, Update, Delete
GET Read
PUT Create, Update
DELETE Delete

I hope thats enough for a theoretical introduction. Now for those who are eager to try cooking some code, here is the recipe.

The Netbeans Tutorial - Getting Started with RESTful Web Services

Tuesday, June 17, 2008

FAINT - Search for faces

Lately, I've been playing around a bit with facial pattern recognition algorithms and their open source implementations. I came across many reference implementation but a very few were implemented in Java, and the Eigenfaces algorithm by far happens to be the best amongst them all. During my research around the said topic i happened to stumble-upon an implementation called FAINT (The Face Annotation Interface - http://faint.sourceforge.net). Faint by far the best facial pattern recognition API and as you must have already guessed, it implements the Eigenfaces algorithm.

Now enough of theory talks, how about implementing an example with faint...? Here is one for all you face-recognition enthusiasts. The following example simply searches for faces in a given photograph and thumbnails them. Now, I know thats not face recognition; but be a little creative here. Once you have the facial thumbnails extracted, its never a big deal to look further in the Faint API and find methods which can help you do the real recognition. :) Now, i was a little lazy to set up a pattern recognition database to left the example to the point of facial extraction only.

The Simple Class which extracts thumbnails -

import de.offis.faint.controller.MainController;
import de.offis.faint.model.ImageModel;
import de.offis.faint.model.Region;
import java.io.File;
import java.io.IOException;
import java.util.Random;

public class Main {

private static final String Imagedir = "C:\\images\\fr";
private static final String faintDir = "C:\\Documents and Settings\\roy\\.faint";
private static final String saperator = "\\";
private static final Random randomGenerator = new Random();
private static final boolean moveThumbnails = true;

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
MainController controller = MainController.getInstance();
if (controller != null) {
controller.setScanWindowSize(1);
ImageModel imageModel = new ImageModel(Imagedir + saperator + "mgrp.jpg");
Region[] regions = controller.detectFaces(imageModel, false);
if (regions != null) {
System.out.println(regions.length + " people in the image...");
for (int i = 0; i < regions.length; i++) {
Region region = regions[i];
region.cacheToDisk();

if (moveThumbnails) {
String cacheFilename = region.getCachedFile();

File file = new File(faintDir + saperator + cacheFilename);
File dir = new File(Imagedir + saperator + "faces");
boolean success = file.renameTo(new File(dir, "face_" + randomGenerator.nextInt() + ".png"));
if (!success) {
System.out.println("Error occured whilst moving " + cacheFilename);
}
}
}
}
}
}
}


Hope somebody out there takes the example further and does something interesting with the learning.