executable jar funktioniert endlich mit opencv-2413
This commit is contained in:
parent
bf0d6267cb
commit
1ee749cc08
Binary file not shown.
Binary file not shown.
|
@ -97,26 +97,6 @@
|
|||
<version>1.6.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenCV -->
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>2.4.13</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/opencv-2413.jar</systemPath>
|
||||
<classifier>native-all</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>2.4.13</version>
|
||||
<scope>system</scope>
|
||||
<type>dll</type>
|
||||
<systemPath>${project.basedir}/libs/x64/opencv_java2413.dll</systemPath>
|
||||
<classifier>native-all</classifier>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -124,6 +104,12 @@
|
|||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openpnp</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>3.2.0-1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -1,13 +1,21 @@
|
|||
import model.Line;
|
||||
import model.LineModel;
|
||||
|
||||
import nu.pattern.OpenCV;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.opencv.core.Core;
|
||||
import presenter.Presenter;
|
||||
import presenter.algorithms.advanced.RepeatedMedianEstimator;
|
||||
import presenter.generator.DatasetGenerator;
|
||||
import view.MainFrame;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static nu.pattern.OpenCV.loadShared;
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
|
@ -67,15 +75,23 @@ public class App {
|
|||
SwingUtilities.updateComponentTreeUI(view);
|
||||
}
|
||||
|
||||
static {
|
||||
nu.pattern.OpenCV.loadShared();
|
||||
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//loadLibrary();
|
||||
|
||||
System.out.println("Welcome to OpenCV " + Core.VERSION);
|
||||
System.out.println(System.getProperty("java.library.path"));
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||
|
||||
final String[] options = {"Normal", "Benchmark"};
|
||||
String chosen = (String) JOptionPane.showInputDialog(null,
|
||||
"Bitte wählen Sie eine Ansicht!",
|
||||
"Ausführungsoptionen",
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (chosen == "Normal"){
|
||||
final Presenter presenter = new Presenter(new LineModel(), null);
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
MainFrame view = new MainFrame();
|
||||
|
@ -84,8 +100,40 @@ public class App {
|
|||
view.setPresenter(presenter);
|
||||
view.setActionListeners();
|
||||
presenter.setView(view);
|
||||
});
|
||||
});} else {
|
||||
benchmark();
|
||||
}
|
||||
}
|
||||
|
||||
public static void benchmark() {
|
||||
int[] sizes = {50, 500, 1000, 3000, 5000, 10000};
|
||||
|
||||
for (int i = 5; i < sizes.length; i++) {
|
||||
System.out.println("---- Datasetgröße: " + sizes[i] + " ----");
|
||||
DatasetGenerator generator = new DatasetGenerator();
|
||||
LinkedList<Line> lines = generator.generateDataCloud(sizes[i]);
|
||||
// IntersectionComputer computer = new IntersectionComputer(lines);
|
||||
// ArrayList<Point> points = computer.compute();
|
||||
|
||||
//algorithms
|
||||
//NaivLeastMedianOfSquaresEstimator naivLms = new NaivLeastMedianOfSquaresEstimator(lines);
|
||||
//naivLms.run();
|
||||
|
||||
// NaivRepeatedMedianEstimator naivRm = new NaivRepeatedMedianEstimator(lines);
|
||||
// naivRm.run();
|
||||
//
|
||||
// NaivTheilSenEstimator naivTs = new NaivTheilSenEstimator(lines);
|
||||
// naivTs.run();
|
||||
|
||||
// LeastMedianOfSquaresEstimator lms = new LeastMedianOfSquaresEstimator(lines,points);
|
||||
// lms.run();
|
||||
|
||||
RepeatedMedianEstimator rm = new RepeatedMedianEstimator(lines);
|
||||
rm.run();
|
||||
|
||||
// TheilSenEstimator ts = new TheilSenEstimator(lines,points);
|
||||
// ts.run();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -196,12 +196,12 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateDataset() {
|
||||
public void generateDataset(int n) {
|
||||
if (generatorThread == null || !generatorThread.isAlive()) {
|
||||
generatorThread = new Thread(() -> {
|
||||
DatasetGenerator generator = new DatasetGenerator();
|
||||
generator.addObserver(this);
|
||||
getModel().setLines(generator.generateCircle(100));
|
||||
getModel().setLines(generator.generateDataCloud(n));
|
||||
calculateIntersections();
|
||||
getView().enableFunctionality();
|
||||
});
|
||||
|
|
|
@ -64,6 +64,11 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
*/
|
||||
public void run() {
|
||||
|
||||
System.out.println("=== S T A R T - L M S ===");
|
||||
long start;
|
||||
long end;
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
//(2.) Let U <- (-inf, inf) be the initial active intervals...
|
||||
Comparator<Interval> comparator = (o1, o2) -> {
|
||||
if (o1.getDistance() < o2.getDistance()) {
|
||||
|
@ -91,7 +96,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
|
||||
//(b.) apply plane sweep
|
||||
if ((constant * n) >= numberOfIntersections) {
|
||||
sigmaMin = planeSweep(interval);
|
||||
sigmaMin = pseudoSweep(interval);
|
||||
} else {
|
||||
//(c.) otherwise....
|
||||
// get random intersections point...
|
||||
|
@ -131,6 +136,8 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
this.intervals.remove(interval);
|
||||
}
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,7 +161,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
* @param interval
|
||||
* @return
|
||||
*/
|
||||
public Line planeSweep(Interval interval) {
|
||||
public Line pseudoSweep(Interval interval) {
|
||||
|
||||
//initialisiere die x-Queue mit den 2D Punkten und sortiere nach x-Lexikographischer Ordnung
|
||||
ArrayList<Point> xQueue = new ArrayList<>();
|
||||
|
|
|
@ -87,6 +87,11 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
*/
|
||||
public void run() {
|
||||
|
||||
System.out.println("=== S T A R T - R M ===");
|
||||
long start;
|
||||
long end;
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
while (linesInCenterSlab.size() != 1) {
|
||||
n = linesInCenterSlab.size();
|
||||
r = Math.ceil(Math.pow(n, beta));
|
||||
|
@ -124,6 +129,8 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
|||
contractIntervals();
|
||||
|
||||
}
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,8 +37,11 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
|||
Double beta;
|
||||
Double alpha;
|
||||
Double dijk;
|
||||
System.out.println("=== S T A R T - naiv L M S ===");
|
||||
long start;
|
||||
long end;
|
||||
start = System.currentTimeMillis();
|
||||
for (Point i : set) {
|
||||
System.out.println(i);
|
||||
for (Point j : set) {
|
||||
for (Point k : set) {
|
||||
triple.add(i);
|
||||
|
@ -58,7 +61,8 @@ public class NaivLeastMedianOfSquaresEstimator implements Algorithm {
|
|||
}
|
||||
}
|
||||
}
|
||||
System.out.printf("Naiv LMS: %6.2f * x + %6.3f\n", m, b);
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,10 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
|||
@Override
|
||||
public void run() {
|
||||
//init the List for the slopes
|
||||
System.out.println("=== S T A R T - naiv R M ===");
|
||||
long start;
|
||||
long end;
|
||||
start = System.currentTimeMillis();
|
||||
for (int j = 0; j < lines.size(); j++) {
|
||||
Line leq = lines.get(j);
|
||||
if (slopesPerLine.get(leq.getId()) == null) {
|
||||
|
@ -79,7 +83,8 @@ public class NaivRepeatedMedianEstimator implements Algorithm {
|
|||
|
||||
medianX = FastElementSelector.randomizedSelect(xMedians, xMedians.size() / 2);
|
||||
medianY = FastElementSelector.randomizedSelect(yMedians, yMedians.size() / 2);
|
||||
System.out.printf("Naiv RM: %6.2f * x + %6.2f \n", medianX, medianY);
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,6 +30,10 @@ public class NaivTheilSenEstimator implements Algorithm {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("=== S T A R T - naiv T S ===");
|
||||
long start;
|
||||
long end;
|
||||
start = System.currentTimeMillis();
|
||||
ArrayList<Double> slopesList = new ArrayList<>();
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
|
@ -56,7 +60,8 @@ public class NaivTheilSenEstimator implements Algorithm {
|
|||
Double median2 = FastElementSelector.randomizedSelect(list2, list2.size() / 2);
|
||||
slope = FastElementSelector.randomizedSelect(slopesList, slopesList.size() / 2);
|
||||
yInterception = median2 - slope * median1;
|
||||
System.out.printf("Naiv TS: %6.2f * x + %6.3f\n", slope, yInterception);
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Zeit: "+ ((end-start)/1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,23 +41,23 @@ public class IntersectionComputer {
|
|||
yMaximum = Double.MIN_VALUE;
|
||||
}
|
||||
|
||||
public ArrayList<Point> compute() {
|
||||
public ArrayList<Point> compute(double lower, double higher) {
|
||||
|
||||
if (lines.size() >= 12) {
|
||||
worker[0] = new Thread(() -> {
|
||||
work(lines.subList(0, (lines.size() / 4)));
|
||||
work(lines.subList(0, (lines.size() / 4)),lower,higher);
|
||||
});
|
||||
worker[0].start();
|
||||
worker[1] = new Thread(() -> {
|
||||
work(lines.subList((lines.size() / 4) + 1, (lines.size() / 2)));
|
||||
work(lines.subList((lines.size() / 4) + 1, (lines.size() / 2)),lower,higher);
|
||||
});
|
||||
worker[1].start();
|
||||
worker[2] = new Thread(() -> {
|
||||
work(lines.subList((lines.size() / 2) + 1, 3 * (lines.size() / 4)));
|
||||
work(lines.subList((lines.size() / 2) + 1, 3 * (lines.size() / 4)),lower,higher);
|
||||
});
|
||||
worker[2].start();
|
||||
worker[3] = new Thread(() -> {
|
||||
work(lines.subList(3 * (lines.size() / 4) + 1, (lines.size())));
|
||||
work(lines.subList(3 * (lines.size() / 4) + 1, (lines.size())),lower,higher);
|
||||
});
|
||||
worker[3].start();
|
||||
|
||||
|
@ -70,16 +70,20 @@ public class IntersectionComputer {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
work(lines);
|
||||
work(lines,lower,higher);
|
||||
}
|
||||
|
||||
return new ArrayList<>(intersections);
|
||||
|
||||
}
|
||||
|
||||
private synchronized void work(List<Line> lines) {
|
||||
public ArrayList<Point> compute() {
|
||||
return compute(-99999, 99999);
|
||||
}
|
||||
|
||||
private synchronized void work(List<Line> lines, double lower, double higher) {
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(lines, new Interval(-99999, 99999));
|
||||
counter.run(lines, new Interval(lower, higher));
|
||||
ArrayList<Point> points = counter.calculateIntersectionAbscissas();
|
||||
for (Point p : points) {
|
||||
if (!isFound(p)) {
|
||||
|
|
|
@ -129,10 +129,6 @@ public class EvaluateAlgorithms extends Observable {
|
|||
ArrayList<String> result;
|
||||
ArrayList<ArrayList<String>> multipleResults = new ArrayList<>();
|
||||
|
||||
startLMS();
|
||||
startRM();
|
||||
startTS();
|
||||
System.out.println("alle advanced algorithmen sind berechnet!");
|
||||
switch (type) {
|
||||
case 0:
|
||||
//der alg der gewählt wurde
|
||||
|
@ -191,6 +187,8 @@ public class EvaluateAlgorithms extends Observable {
|
|||
ArrayList<Double[]> lineRes;
|
||||
switch (alg) {
|
||||
case 3:
|
||||
startLMS();
|
||||
startRM();
|
||||
|
||||
result = getPercentigeErrorBasedMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1]);
|
||||
multipleResults.add(result);
|
||||
|
@ -206,6 +204,9 @@ public class EvaluateAlgorithms extends Observable {
|
|||
|
||||
break;
|
||||
case 4:
|
||||
startLMS();
|
||||
startTS();
|
||||
|
||||
result = getPercentigeErrorBasedMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1]);
|
||||
multipleResults.add(result);
|
||||
result = fillPseudoResults();
|
||||
|
@ -219,6 +220,9 @@ public class EvaluateAlgorithms extends Observable {
|
|||
sendPloteLineResults(lineRes, new Integer[]{0, 2});
|
||||
break;
|
||||
case 5:
|
||||
startRM();
|
||||
startTS();
|
||||
|
||||
result = fillPseudoResults();
|
||||
multipleResults.add(result);
|
||||
result = getPercentigeErrorBasedMeasure(arrangement.getLines(), rmRes[0], rmRes[1]);
|
||||
|
@ -232,6 +236,10 @@ public class EvaluateAlgorithms extends Observable {
|
|||
sendPloteLineResults(lineRes, new Integer[]{1, 2});
|
||||
break;
|
||||
case 6:
|
||||
startLMS();
|
||||
startRM();
|
||||
startTS();
|
||||
|
||||
result = getPercentigeErrorBasedMeasure(arrangement.getLines(), lmsRes[0], lmsRes[1]);
|
||||
multipleResults.add(result);
|
||||
result = getPercentigeErrorBasedMeasure(arrangement.getLines(), rmRes[0], rmRes[1]);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package presenter.evaluation;
|
||||
|
||||
import model.Line;
|
||||
|
||||
import org.opencv.core.*;
|
||||
import org.opencv.highgui.Highgui;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import presenter.Presenter;
|
||||
|
||||
|
@ -35,7 +36,7 @@ public class PictureProcessor extends Observable {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
image = Highgui.imread(file.getAbsolutePath());
|
||||
image = Imgcodecs.imread(file.getAbsolutePath());
|
||||
contour = process(image);
|
||||
contourLength = image.width() * 0.3;
|
||||
createInputData();
|
||||
|
@ -44,12 +45,12 @@ public class PictureProcessor extends Observable {
|
|||
private Mat process(Mat image) {
|
||||
Mat threshold = new Mat(image.width(), image.height(), CvType.CV_8UC1);
|
||||
Mat source = new Mat(image.width(), image.height(), CvType.CV_8UC1);
|
||||
Highgui.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-orig.png", image);
|
||||
Imgcodecs.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-orig.png", image);
|
||||
Imgproc.cvtColor(image, source, Imgproc.COLOR_BGR2GRAY);
|
||||
Highgui.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Greyscale.png", source);
|
||||
Imgcodecs.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Greyscale.png", source);
|
||||
Imgproc.GaussianBlur(source, threshold, new Size(3, 3), 0, 0);
|
||||
Imgproc.Canny(threshold, source, 300, 600, 5, true);
|
||||
Highgui.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Canny.png", source);
|
||||
Imgcodecs.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Canny.png", source);
|
||||
//Konturen berechnen und filtern
|
||||
contours = new ArrayList<>();
|
||||
Imgproc.findContours(source, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
|
||||
|
@ -62,7 +63,7 @@ public class PictureProcessor extends Observable {
|
|||
Imgproc.drawContours(viscont, contours, i, new Scalar(255, 0, 0), 1);
|
||||
}
|
||||
}
|
||||
Highgui.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Contour.png", viscont);
|
||||
Imgcodecs.imwrite(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("."))+"-Contour.png", viscont);
|
||||
Mat resized = new Mat();
|
||||
Imgproc.resize(viscont, resized, new Size(560, 560));
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DatasetGenerator extends Observable {
|
|||
line.setId(i - 1 + "");
|
||||
lines.add(line);
|
||||
}
|
||||
String[] ret = {"generator", "Es wurden " + 100 + " Daten generiert mit den Parametern",
|
||||
String[] ret = {"generator", "Es wurden " + size + " Daten generiert mit den Parametern",
|
||||
"</br> <b>m</b> = " + m + "",
|
||||
"</br> <b>b</b> = " + b + ""};
|
||||
setChanged();
|
||||
|
@ -89,7 +89,7 @@ public class DatasetGenerator extends Observable {
|
|||
idx++;
|
||||
}
|
||||
|
||||
String[] ret = {"generator", "Es wurden " + 100 + " Daten generiert mit den Parametern"};
|
||||
String[] ret = {"generator", "Es wurden " + n + " Daten generiert mit den Parametern"};
|
||||
setChanged();
|
||||
notifyObservers(ret);
|
||||
return lines;
|
||||
|
|
|
@ -2,8 +2,13 @@ package view.listener;
|
|||
|
||||
import presenter.Presenter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -16,6 +21,7 @@ import java.awt.event.ActionListener;
|
|||
public class GenerateDataListener implements ActionListener {
|
||||
|
||||
private Presenter presenter;
|
||||
private JDialog dialog;
|
||||
|
||||
public GenerateDataListener(Presenter presenter) {
|
||||
this.presenter = presenter;
|
||||
|
@ -23,7 +29,34 @@ public class GenerateDataListener implements ActionListener {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Thread t = new Thread(() -> presenter.generateDataset());
|
||||
t.start();
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
||||
if (dialog == null || !dialog.isVisible()) {
|
||||
dialog = new JDialog();
|
||||
dialog.setAlwaysOnTop(true);
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.getDefault());
|
||||
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
|
||||
decimalFormat.setGroupingUsed(false);
|
||||
JTextField textField = new JFormattedTextField(decimalFormat);
|
||||
textField.setColumns(20);
|
||||
JButton aproveButton = new JButton("start");
|
||||
dialog.setSize(350, 70);
|
||||
dialog.setLayout(new FlowLayout());
|
||||
dialog.setResizable(false);
|
||||
dialog.setLocationRelativeTo(presenter.getView());
|
||||
dialog.add(textField);
|
||||
dialog.add(aproveButton);
|
||||
aproveButton.addActionListener(e1 -> {
|
||||
int n = Integer.parseInt(textField.getText());
|
||||
Thread t = new Thread(() -> presenter.generateDataset(n));
|
||||
t.start();
|
||||
dialog.dispose();
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue