Using OpenIMAJ within Groovy code is really easy. Just use Grape annotations or method calls to download and link the OpenIMAJ jars automatically. You also need to specify the repository from which to download the OpenIMAJ jars using the GrabResolver method or annotation:


The following code demonstrates how difference-of-Gaussian SIFT features can be extracted in a simple Groovy program:

import org.openimaj.image.*
import org.openimaj.image.colour.*
import org.openimaj.math.geometry.shape.*

import org.openimaj.image.feature.local.engine.*

//Load an image
img = ImageUtilities.readMBF( args.length>0 ? 
              new File(args[0]) : 

//create a default difference-of-Gaussian SIFT extraction engine
engine = new DoGSIFTEngine()

//extract the features
features = engine.findFeatures(Transforms.calculateIntensityNTSC(img))

//draw the regions
features.each { feature ->
    img.drawShape(new Circle(feature.x, feature.y, feature.scale), RGBColour.RED)

//display the result

//write to standard output in the format used by Lowe's tool
IOUtils.writeASCII(System.out, features)

The above code can be copied into the groovyConsole application and run directly:

SIFT Extraction in Groovy

Additional examples of using OpenIMAJ in Groovy can be found in the GroovyDemo folder at /trunk/demo/GroovyDemo in the source repository.