Java examples for Machine Learning AI:openimaj
Object Feature Extraction from Image using openimaj
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 ObjectFeatureExtraction { public static void main(String args[]) throws IOException { String inputFolder = "data/"; String inputImage = "bird.jpg"; String outputFolder = "output/"; String[] IMAGE_CATEGORIES = { "Beaver", "Bird", "SeaLion" }; int input_class = 2; MBFImage mbfImage = ImageUtilities.readMBF(new File(inputFolder + inputImage));//from w ww. j a va 2s . c o 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(); } }