Skip to content

Commit

Permalink
start Javafx classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeybesse committed Apr 18, 2017
1 parent 6c391b9 commit 61189ec
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 27 deletions.
6 changes: 5 additions & 1 deletion gs-cv/.classpath
Expand Up @@ -18,6 +18,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Opencv-3.2.0"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Opencv-3.2.0">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="/home/middleware/opencv/build/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
26 changes: 0 additions & 26 deletions gs-cv/pom.xml
Expand Up @@ -13,32 +13,6 @@

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin.version}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
</plugin>
</plugins>
</build>

<dependencies>
Expand Down
91 changes: 91 additions & 0 deletions gs-cv/src/main/java/org/genericsystem/cv/ClassifierDemo.java
@@ -0,0 +1,91 @@
package org.genericsystem.cv;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class ClassifierDemo extends Application {

private final static String sourceDirectoryPath = "png";
private final double displayWidth = 200d;

static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) throws Exception {

GridPane gridPane = new GridPane();

List<File> images = Arrays.stream(new File(sourceDirectoryPath).listFiles()).filter(img -> img.getName().endsWith(".png")).collect(Collectors.toList());

int row = 0;

for (File img1 : images) {
int column = 0;
File img2 = images.get(0);
Mat mat1 = Imgcodecs.imread(img1.getPath());
gridPane.add(getImageViewFromMat(mat1), column++, row);
Integer result = Classifier.compareFeature(img1.getPath(), img2.getPath());
gridPane.add(new Label(result.toString()), column++, row);
row++;
}
Scene scene = new Scene(new Group());
stage.setTitle("Generic System Computer Vision");
ScrollPane scrollPane = new ScrollPane(gridPane);
scrollPane.setFitToHeight(true);
VBox root = new VBox(scrollPane);
scene.setRoot(root);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
try {
stop();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
stage.setScene(scene);
stage.show();
}

private ImageView getImageViewFromMat(Mat src) {
Mat target = new Mat();
Imgproc.resize(src, target, new Size(displayWidth, Math.floor((displayWidth / src.width()) * src.height())));
MatOfByte buffer = new MatOfByte();
Imgcodecs.imencode(".png", target, buffer);
ImageView imageView = new ImageView(new Image(new ByteArrayInputStream(buffer.toArray())));
imageView.setPreserveRatio(true);
imageView.setFitWidth(displayWidth);
return imageView;
}

}

0 comments on commit 61189ec

Please sign in to comment.