Get Object Feature using openimaj - Java Machine Learning AI

Java examples for Machine Learning AI:openimaj

Description

Get Object Feature using openimaj

Demo Code

import org.openimaj.feature.local.list.LocalFeatureList;
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.MBFImage;
import org.openimaj.image.feature.local.engine.DoGSIFTEngine;
import org.openimaj.image.feature.local.keypoints.Keypoint;

import java.io.*;


public class ObjectFeature {
    public static void main(String args[]) throws IOException {
        String inputFolder = "data/";
        String inputImage = "test.jpg";
        String outputFolder = "output/";
        String[] IMAGE_CATEGORIES = { "Horse", "Bird", "SeaLion", "Swan","Beaver" };
        int input_class = 2;
        MBFImage mbfImage = ImageUtilities.readMBF(new File(inputFolder
                + inputImage));/*from   www .ja v  a  2s  .co  m*/
        DoGSIFTEngine doGSIFTEngine = new DoGSIFTEngine();
        LocalFeatureList<Keypoint> features = doGSIFTEngine
                .findFeatures(mbfImage.flatten());
        FileWriter fw = new FileWriter(outputFolder
                + IMAGE_CATEGORIES[input_class] + ".txt");
        BufferedWriter bw = new BufferedWriter(fw);
        for (int i = 0; i < features.size(); i++) {
            double c[] = features.get(i).getFeatureVector()
                    .asDoubleVector();
            bw.write(input_class + ",");
            for (int j = 0; j < c.length; j++) {
                bw.write(c[j] + " ");
            }
            bw.newLine();
        }
        bw.close();
    }
}

Related Tutorials