ts funktioniert jetzt auch auf bildern

This commit is contained in:
Armin Wolf 2017-09-23 14:13:09 +02:00
parent 26f8dd6d71
commit bf0d6267cb
11 changed files with 419 additions and 46 deletions

View File

@ -0,0 +1,4 @@
path.variable.kotlin_bundled=C\:\\Program Files\\JetBrains\\IntelliJ IDEA 2017.2.3\\plugins\\Kotlin\\kotlinc
path.variable.maven_repository=C\:\\Users\\Armin\\.m2\\repository
jdk.home.1.8=C\:/Program Files/Java/jdk1.8.0_121
javac2.instrumentation.includeJavaRuntime=false

View File

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="masterarbeit" default="all">
<property file="masterarbeit.properties"/>
<!-- Uncomment the following property if no tests compilation is needed -->
<!--
<property name="skip.tests" value="true"/>
-->
<!-- Compiler options -->
<property name="compiler.debug" value="on"/>
<property name="compiler.generate.no.warnings" value="off"/>
<property name="compiler.args" value=""/>
<property name="compiler.max.memory" value="6500m"/>
<patternset id="ignored.files">
<exclude name="**/*.hprof/**"/>
<exclude name="**/*.pyc/**"/>
<exclude name="**/*.pyo/**"/>
<exclude name="**/*.rbc/**"/>
<exclude name="**/*.yarb/**"/>
<exclude name="**/*~/**"/>
<exclude name="**/.DS_Store/**"/>
<exclude name="**/.git/**"/>
<exclude name="**/.hg/**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/CVS/**"/>
<exclude name="**/__pycache__/**"/>
<exclude name="**/_svn/**"/>
<exclude name="**/vssver.scc/**"/>
<exclude name="**/vssver2.scc/**"/>
</patternset>
<patternset id="library.patterns">
<include name="*.egg"/>
<include name="*.jar"/>
<include name="*.ear"/>
<include name="*.swc"/>
<include name="*.war"/>
<include name="*.ane"/>
<include name="*.zip"/>
</patternset>
<patternset id="compiler.resources">
<exclude name="**/?*.java"/>
<exclude name="**/?*.form"/>
<exclude name="**/?*.class"/>
<exclude name="**/?*.groovy"/>
<exclude name="**/?*.scala"/>
<exclude name="**/?*.flex"/>
<exclude name="**/?*.kt"/>
<exclude name="**/?*.clj"/>
<exclude name="**/?*.aj"/>
</patternset>
<!-- JDK definitions -->
<property name="jdk.bin.1.8" value="${jdk.home.1.8}/bin"/>
<path id="jdk.classpath.1.8">
<fileset dir="${jdk.home.1.8}">
<include name="jre/lib/charsets.jar"/>
<include name="jre/lib/deploy.jar"/>
<include name="jre/lib/ext/access-bridge-64.jar"/>
<include name="jre/lib/ext/cldrdata.jar"/>
<include name="jre/lib/ext/dnsns.jar"/>
<include name="jre/lib/ext/jaccess.jar"/>
<include name="jre/lib/ext/jfxrt.jar"/>
<include name="jre/lib/ext/localedata.jar"/>
<include name="jre/lib/ext/nashorn.jar"/>
<include name="jre/lib/ext/sunec.jar"/>
<include name="jre/lib/ext/sunjce_provider.jar"/>
<include name="jre/lib/ext/sunmscapi.jar"/>
<include name="jre/lib/ext/sunpkcs11.jar"/>
<include name="jre/lib/ext/zipfs.jar"/>
<include name="jre/lib/javaws.jar"/>
<include name="jre/lib/jce.jar"/>
<include name="jre/lib/jfr.jar"/>
<include name="jre/lib/jfxswt.jar"/>
<include name="jre/lib/jsse.jar"/>
<include name="jre/lib/management-agent.jar"/>
<include name="jre/lib/plugin.jar"/>
<include name="jre/lib/resources.jar"/>
<include name="jre/lib/rt.jar"/>
</fileset>
</path>
<property name="project.jdk.home" value="${jdk.home.1.8}"/>
<property name="project.jdk.bin" value="${jdk.bin.1.8}"/>
<property name="project.jdk.classpath" value="jdk.classpath.1.8"/>
<!-- Project Libraries -->
<path id="library.maven:_bouncycastle:bcmail-jdk14:138.classpath">
<pathelement location="${path.variable.maven_repository}/bouncycastle/bcmail-jdk14/138/bcmail-jdk14-138.jar"/>
</path>
<path id="library.maven:_bouncycastle:bcprov-jdk14:138.classpath">
<pathelement location="${path.variable.maven_repository}/bouncycastle/bcprov-jdk14/138/bcprov-jdk14-138.jar"/>
</path>
<path id="library.maven:_com.jtattoo:jtattoo:1.6.11.classpath">
<pathelement location="${path.variable.maven_repository}/com/jtattoo/JTattoo/1.6.11/JTattoo-1.6.11.jar"/>
</path>
<path id="library.maven:_com.lowagie:itext:2.1.5.classpath">
<pathelement location="${path.variable.maven_repository}/com/lowagie/itext/2.1.5/itext-2.1.5.jar"/>
</path>
<path id="library.maven:_com.opencsv:opencsv:3.9.classpath">
<pathelement location="${path.variable.maven_repository}/com/opencsv/opencsv/3.9/opencsv-3.9.jar"/>
</path>
<path id="library.maven:_commons-beanutils:commons-beanutils:1.9.3.classpath">
<pathelement location="${path.variable.maven_repository}/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar"/>
</path>
<path id="library.maven:_commons-collections:commons-collections:3.2.2.classpath">
<pathelement location="${path.variable.maven_repository}/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar"/>
</path>
<path id="library.maven:_commons-io:commons-io:1.3.2.classpath">
<pathelement location="${path.variable.maven_repository}/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar"/>
</path>
<path id="library.maven:_commons-logging:commons-logging:1.2.classpath">
<pathelement location="${path.variable.maven_repository}/commons-logging/commons-logging/1.2/commons-logging-1.2.jar"/>
</path>
<path id="library.maven:_junit:junit:4.12.classpath">
<pathelement location="${path.variable.maven_repository}/junit/junit/4.12/junit-4.12.jar"/>
</path>
<path id="library.maven:_org.apache.commons:commons-lang3:3.5.classpath">
<pathelement location="${path.variable.maven_repository}/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"/>
</path>
<path id="library.maven:_org.hamcrest:hamcrest-core:1.3.classpath">
<pathelement location="${path.variable.maven_repository}/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
</path>
<path id="library.maven:_org.jfree:jcommon:1.0.17.classpath">
<pathelement location="${path.variable.maven_repository}/org/jfree/jcommon/1.0.17/jcommon-1.0.17.jar"/>
</path>
<path id="library.maven:_org.jfree:jfreechart:1.0.14.classpath">
<pathelement location="${path.variable.maven_repository}/org/jfree/jfreechart/1.0.14/jfreechart-1.0.14.jar"/>
</path>
<path id="library.maven:_org:opencv:2.4.13.classpath">
<pathelement location="${path.variable.maven_repository}/org/opencv/2.4.13/opencv-2.4.13.jar"/>
</path>
<path id="library.maven:_xml-apis:xml-apis:1.3.04.classpath">
<pathelement location="${path.variable.maven_repository}/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar"/>
</path>
<!-- Register Custom Compiler Taskdefs -->
<property name="javac2.home" value="${idea.home}/lib"/>
<path id="javac2.classpath">
<pathelement location="${javac2.home}/javac2.jar"/>
<pathelement location="${javac2.home}/jdom.jar"/>
<pathelement location="${javac2.home}/asm-all.jar"/>
<pathelement location="${javac2.home}/jgoodies-forms.jar"/>
</path>
<target name="register.custom.compilers">
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.classpath"/>
<taskdef name="instrumentIdeaExtensions" classname="com.intellij.ant.InstrumentIdeaExtensions" classpathref="javac2.classpath"/>
</target>
<!-- Modules -->
<import file="${basedir}/module_masterarbeit.xml"/>
<target name="init" description="Build initialization">
<!-- Perform any build initialization in this target -->
</target>
<target name="clean" depends="clean.module.masterarbeit" description="cleanup all"/>
<target name="build.modules" depends="init, clean, compile.module.masterarbeit" description="build all modules"/>
<target name="all" depends="build.modules" description="build all"/>
</project>

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="module_masterarbeit" default="compile.module.masterarbeit">
<dirname property="module.masterarbeit.basedir" file="${ant.file.module_masterarbeit}"/>
<property name="module.jdk.home.masterarbeit" value="${project.jdk.home}"/>
<property name="module.jdk.bin.masterarbeit" value="${project.jdk.bin}"/>
<property name="module.jdk.classpath.masterarbeit" value="${project.jdk.classpath}"/>
<property name="compiler.args.masterarbeit" value="-encoding UTF-8 -source 1.8 -target 1.8 ${compiler.args}"/>
<property name="masterarbeit.output.dir" value="${module.masterarbeit.basedir}/target/classes"/>
<property name="masterarbeit.testoutput.dir" value="${module.masterarbeit.basedir}/target/test-classes"/>
<path id="masterarbeit.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>
<path id="masterarbeit.module.production.classpath">
<path refid="${module.jdk.classpath.masterarbeit}"/>
<pathelement location="${basedir}/../../../Downloads/opencv/build/java/opencv-2413.jar"/>
<pathelement location="${basedir}/libs/opencv-2413.jar"/>
<path refid="library.maven:_org.jfree:jfreechart:1.0.14.classpath"/>
<path refid="library.maven:_org.jfree:jcommon:1.0.17.classpath"/>
<path refid="library.maven:_xml-apis:xml-apis:1.3.04.classpath"/>
<path refid="library.maven:_com.lowagie:itext:2.1.5.classpath"/>
<path refid="library.maven:_bouncycastle:bcmail-jdk14:138.classpath"/>
<path refid="library.maven:_bouncycastle:bcprov-jdk14:138.classpath"/>
<path refid="library.maven:_junit:junit:4.12.classpath"/>
<path refid="library.maven:_org.hamcrest:hamcrest-core:1.3.classpath"/>
<path refid="library.maven:_com.opencsv:opencsv:3.9.classpath"/>
<path refid="library.maven:_org.apache.commons:commons-lang3:3.5.classpath"/>
<path refid="library.maven:_commons-beanutils:commons-beanutils:1.9.3.classpath"/>
<path refid="library.maven:_commons-logging:commons-logging:1.2.classpath"/>
<path refid="library.maven:_commons-collections:commons-collections:3.2.2.classpath"/>
<path refid="library.maven:_com.jtattoo:jtattoo:1.6.11.classpath"/>
<path refid="library.maven:_org:opencv:2.4.13.classpath"/>
<path refid="library.maven:_commons-io:commons-io:1.3.2.classpath"/>
</path>
<path id="masterarbeit.runtime.production.module.classpath">
<pathelement location="${masterarbeit.output.dir}"/>
<pathelement location="${basedir}/../../../Downloads/opencv/build/java/opencv-2413.jar"/>
<pathelement location="${basedir}/libs/opencv-2413.jar"/>
<path refid="library.maven:_org.jfree:jfreechart:1.0.14.classpath"/>
<path refid="library.maven:_org.jfree:jcommon:1.0.17.classpath"/>
<path refid="library.maven:_xml-apis:xml-apis:1.3.04.classpath"/>
<path refid="library.maven:_com.lowagie:itext:2.1.5.classpath"/>
<path refid="library.maven:_bouncycastle:bcmail-jdk14:138.classpath"/>
<path refid="library.maven:_bouncycastle:bcprov-jdk14:138.classpath"/>
<path refid="library.maven:_junit:junit:4.12.classpath"/>
<path refid="library.maven:_org.hamcrest:hamcrest-core:1.3.classpath"/>
<path refid="library.maven:_com.opencsv:opencsv:3.9.classpath"/>
<path refid="library.maven:_org.apache.commons:commons-lang3:3.5.classpath"/>
<path refid="library.maven:_commons-beanutils:commons-beanutils:1.9.3.classpath"/>
<path refid="library.maven:_commons-logging:commons-logging:1.2.classpath"/>
<path refid="library.maven:_commons-collections:commons-collections:3.2.2.classpath"/>
<path refid="library.maven:_com.jtattoo:jtattoo:1.6.11.classpath"/>
<path refid="library.maven:_org:opencv:2.4.13.classpath"/>
<path refid="library.maven:_commons-io:commons-io:1.3.2.classpath"/>
</path>
<path id="masterarbeit.module.classpath">
<path refid="${module.jdk.classpath.masterarbeit}"/>
<pathelement location="${masterarbeit.output.dir}"/>
<pathelement location="${basedir}/../../../Downloads/opencv/build/java/opencv-2413.jar"/>
<pathelement location="${basedir}/libs/opencv-2413.jar"/>
<path refid="library.maven:_org.jfree:jfreechart:1.0.14.classpath"/>
<path refid="library.maven:_org.jfree:jcommon:1.0.17.classpath"/>
<path refid="library.maven:_xml-apis:xml-apis:1.3.04.classpath"/>
<path refid="library.maven:_com.lowagie:itext:2.1.5.classpath"/>
<path refid="library.maven:_bouncycastle:bcmail-jdk14:138.classpath"/>
<path refid="library.maven:_bouncycastle:bcprov-jdk14:138.classpath"/>
<path refid="library.maven:_junit:junit:4.12.classpath"/>
<path refid="library.maven:_org.hamcrest:hamcrest-core:1.3.classpath"/>
<path refid="library.maven:_com.opencsv:opencsv:3.9.classpath"/>
<path refid="library.maven:_org.apache.commons:commons-lang3:3.5.classpath"/>
<path refid="library.maven:_commons-beanutils:commons-beanutils:1.9.3.classpath"/>
<path refid="library.maven:_commons-logging:commons-logging:1.2.classpath"/>
<path refid="library.maven:_commons-collections:commons-collections:3.2.2.classpath"/>
<path refid="library.maven:_com.jtattoo:jtattoo:1.6.11.classpath"/>
<path refid="library.maven:_org:opencv:2.4.13.classpath"/>
<path refid="library.maven:_commons-io:commons-io:1.3.2.classpath"/>
</path>
<path id="masterarbeit.runtime.module.classpath">
<pathelement location="${masterarbeit.testoutput.dir}"/>
<pathelement location="${masterarbeit.output.dir}"/>
<pathelement location="${basedir}/../../../Downloads/opencv/build/java/opencv-2413.jar"/>
<pathelement location="${basedir}/libs/opencv-2413.jar"/>
<path refid="library.maven:_org.jfree:jfreechart:1.0.14.classpath"/>
<path refid="library.maven:_org.jfree:jcommon:1.0.17.classpath"/>
<path refid="library.maven:_xml-apis:xml-apis:1.3.04.classpath"/>
<path refid="library.maven:_com.lowagie:itext:2.1.5.classpath"/>
<path refid="library.maven:_bouncycastle:bcmail-jdk14:138.classpath"/>
<path refid="library.maven:_bouncycastle:bcprov-jdk14:138.classpath"/>
<path refid="library.maven:_junit:junit:4.12.classpath"/>
<path refid="library.maven:_org.hamcrest:hamcrest-core:1.3.classpath"/>
<path refid="library.maven:_com.opencsv:opencsv:3.9.classpath"/>
<path refid="library.maven:_org.apache.commons:commons-lang3:3.5.classpath"/>
<path refid="library.maven:_commons-beanutils:commons-beanutils:1.9.3.classpath"/>
<path refid="library.maven:_commons-logging:commons-logging:1.2.classpath"/>
<path refid="library.maven:_commons-collections:commons-collections:3.2.2.classpath"/>
<path refid="library.maven:_com.jtattoo:jtattoo:1.6.11.classpath"/>
<path refid="library.maven:_org:opencv:2.4.13.classpath"/>
<path refid="library.maven:_commons-io:commons-io:1.3.2.classpath"/>
</path>
<patternset id="excluded.from.module.masterarbeit">
<patternset refid="ignored.files"/>
</patternset>
<patternset id="excluded.from.compilation.masterarbeit">
<patternset refid="excluded.from.module.masterarbeit"/>
</patternset>
<path id="masterarbeit.module.sourcepath">
<dirset dir="${module.masterarbeit.basedir}">
<include name="src/main/java"/>
<include name="src/main/resources"/>
</dirset>
</path>
<path id="masterarbeit.module.test.sourcepath">
<dirset dir="${module.masterarbeit.basedir}">
<include name="src/test/java"/>
</dirset>
</path>
<target name="compile.module.masterarbeit" depends="compile.module.masterarbeit.production,compile.module.masterarbeit.tests" description="Compile module masterarbeit"/>
<target name="compile.module.masterarbeit.production" depends="register.custom.compilers" description="Compile module masterarbeit; production classes">
<mkdir dir="${masterarbeit.output.dir}"/>
<javac2 destdir="${masterarbeit.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.masterarbeit}/javac">
<compilerarg line="${compiler.args.masterarbeit}"/>
<bootclasspath refid="masterarbeit.module.bootclasspath"/>
<classpath refid="masterarbeit.module.production.classpath"/>
<src refid="masterarbeit.module.sourcepath"/>
<patternset refid="excluded.from.compilation.masterarbeit"/>
</javac2>
<copy todir="${masterarbeit.output.dir}">
<fileset dir="${module.masterarbeit.basedir}/src/main/java">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
<fileset dir="${module.masterarbeit.basedir}/src/main/resources">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>
<target name="compile.module.masterarbeit.tests" depends="register.custom.compilers,compile.module.masterarbeit.production" description="compile module masterarbeit; test classes" unless="skip.tests">
<mkdir dir="${masterarbeit.testoutput.dir}"/>
<javac2 destdir="${masterarbeit.testoutput.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.masterarbeit}/javac">
<compilerarg line="${compiler.args.masterarbeit}"/>
<bootclasspath refid="masterarbeit.module.bootclasspath"/>
<classpath refid="masterarbeit.module.classpath"/>
<src refid="masterarbeit.module.test.sourcepath"/>
<patternset refid="excluded.from.compilation.masterarbeit"/>
</javac2>
<copy todir="${masterarbeit.testoutput.dir}">
<fileset dir="${module.masterarbeit.basedir}/src/test/java">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>
<target name="clean.module.masterarbeit" description="cleanup module">
<delete dir="${masterarbeit.output.dir}"/>
<delete dir="${masterarbeit.testoutput.dir}"/>
</target>
</project>

View File

@ -102,7 +102,9 @@
<groupId>org</groupId>
<artifactId>opencv</artifactId>
<version>2.4.13</version>
<systemPath>${project.basedir}/src/main/resources/libs/opencv-2413.jar</systemPath>
<scope>system</scope>
<systemPath>${project.basedir}/libs/opencv-2413.jar</systemPath>
<classifier>native-all</classifier>
</dependency>
<dependency>
@ -111,16 +113,17 @@
<version>2.4.13</version>
<scope>system</scope>
<type>dll</type>
<systemPath>${project.basedir}/src/main/resources/libs/x64/opencv_java2413.dll</systemPath>
<systemPath>${project.basedir}/libs/x64/opencv_java2413.dll</systemPath>
<classifier>native-all</classifier>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<version>2.5</version>
</dependency>
</dependencies>
</project>

View File

@ -7,10 +7,7 @@ import view.MainFrame;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
@ -21,23 +18,13 @@ import java.io.OutputStream;
*/
public class App {
private static void loadLibrary() {
try {
InputStream in = null;
File fileOut = null;
String osName = System.getProperty("os.name");
int bitness = Integer.parseInt(System.getProperty("sun.arch.data.model"));
if(bitness == 32){
in = App.class.getResourceAsStream("/libs/x86/opencv_java2413.dll");
fileOut = File.createTempFile("tmp", ".dll");
}
else if (bitness == 64){
in = App.class.getResourceAsStream("/libs/x64/opencv_java2413.dll");
fileOut = File.createTempFile("tmp", ".dll");
}
in = App.class.getResourceAsStream("/libs/x64/opencv_java2413.dll");
fileOut = File.createTempFile("tmp", ".dll");
OutputStream out = new FileOutputStream(fileOut);
IOUtils.copy(in, out);
@ -81,7 +68,11 @@ public class App {
}
public static void main(String[] args) {
loadLibrary();
//loadLibrary();
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.out.println(System.getProperty("java.library.path"));
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
final Presenter presenter = new Presenter(new LineModel(), null);

View File

@ -5,9 +5,7 @@ import model.Line;
import model.Point;
import presenter.Presenter;
import presenter.algorithms.Algorithm;
import presenter.algorithms.util.BinomialCoeffizient;
import presenter.algorithms.util.FastElementSelector;
import presenter.algorithms.util.RandomSampler;
import presenter.algorithms.util.*;
import java.util.*;
@ -58,7 +56,8 @@ public class TheilSenEstimator extends Observable implements Algorithm {
this.yCoordinates = new ArrayList<>();
this.xCoordinates = new ArrayList<>();
this.N = BinomialCoeffizient.run(n, 2);
this.k = Integer.valueOf((int) (N * 0.5)) - 1;
//this.k = Integer.valueOf((int) (N * 0.5)) - 1;
this.k = (int) (N / 2);
}
public TheilSenEstimator(LinkedList<Line> setOfLines, ArrayList<Point> setOfIntersections) {
@ -120,8 +119,8 @@ public class TheilSenEstimator extends Observable implements Algorithm {
//Double kthElement = FastElementSelector.randomizedSelect(xCoordinates, k);
//Boolean cond1 = (kthElement > aVariant) && (kthElement <= bVariant);
int lowerCount = getIntervalSize(NEGATIV_INF, aVariant, setOfIntersections);
int higherCount = getIntervalSize(NEGATIV_INF, bVariant, setOfIntersections);
int lowerCount = getIntervalSize(NEGATIV_INF, aVariant);
int higherCount = getIntervalSize(NEGATIV_INF, bVariant);
Boolean conda = k > lowerCount;
Boolean condb = k <= higherCount;
@ -142,20 +141,18 @@ public class TheilSenEstimator extends Observable implements Algorithm {
* @param b obere Grenze des Intrvals
* @return Anzahl der Schnittpunkte im Interval [a,b)
*/
public int getIntervalSize(double a, double b, ArrayList<Point> set) {
int counter = 0;
for (Point x : set) {
if (x.getX() >= a && x.getX() < b) {
counter++;
}
}
return counter;
public int getIntervalSize(double a, double b) {
IntersectionCounter ic = new IntersectionCounter();
return ic.run(setOfLines, new Interval(a,b));
}
/**
* Berechne wieviele von den Schnittpunkten in dem Interval zwischen <code>a</code> und <code>b</code>
* enthalten sind.
*
* Inspiriert durch:
* <url>https://stackoverflow.com/questions/136474/best-way-to-pick-a-random-subset-from-a-collection</url>
*
* @param a untere Grenze des Intervals
* @param b obere Grenze des Intrvals
* @return Anzahl der Schnittpunkte im Interval (a,b)

View File

@ -4,6 +4,8 @@ import model.Line;
import model.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
@ -43,14 +45,27 @@ public class RandomSampler {
public static ArrayList<Double> run(ArrayList<Point> set, Double r) {
ArrayList<Double> sampledLines = new ArrayList<>();
Integer indexOfEnd = set.size();
// Integer indexOfEnd = set.size()-1;
//
// for (int i = 0; i < r; i++) {
// sampledLines.add(set.get(ThreadLocalRandom.current().nextInt(0, indexOfEnd)).getX());
// }
for (int i = 0; i < r; i++) {
Double px = set.get(ThreadLocalRandom.current().nextInt(0, indexOfEnd)).getX();
if (!sampledLines.contains(px))
sampledLines.add(px);
// return sampledLines;
for (Point p : set){
sampledLines.add(p.getX());
}
return sampledLines;
Random rand = new Random();
int inputSize = sampledLines.size();
for (int i = 0; i < r; i++)
{
int indexToSwap = i + rand.nextInt(inputSize - i);
Double temp = sampledLines.get(i);
sampledLines.set(i, sampledLines.get(indexToSwap));
sampledLines.set(indexToSwap, temp);
}
return new ArrayList<>(sampledLines.subList(0, r.intValue()));
}
}

View File

@ -44,9 +44,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);
Imgproc.cvtColor(image, source, Imgproc.COLOR_BGR2GRAY);
Highgui.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);
//Konturen berechnen und filtern
contours = new ArrayList<>();
Imgproc.findContours(source, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
@ -59,6 +62,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);
Mat resized = new Mat();
Imgproc.resize(viscont, resized, new Size(560, 560));
SwingUtilities.invokeLater(() -> {
@ -70,7 +74,7 @@ public class PictureProcessor extends Observable {
dialog.add(label);
dialog.setVisible(true);
});
return source;
return viscont;
}

View File

@ -39,14 +39,14 @@ public class EvalResultLatexExport {
private String createOutputData() {
String split = "&";
StringBuilder doc = new StringBuilder();
doc.append("\\begin{tabular}{l|*{3}{r}}" + "\r\n");
doc.append("\\begin{tabular}{|l|r|r|r|}" + "\\hline\r\n");
for (int i = 0; i < model.getColumnCount(); i++) {
if (model.getValueAt(0, i).toString() != "" || model.getRowCount() > 5)
doc.append("\\textsc{" + model.getColumnName(i) + "}" + split);
}
doc.deleteCharAt(doc.lastIndexOf(split));
doc.append("\\\\\\hline\\hline" + "\r\n");
doc.append("\\\\\\hline" + "\r\n");
for (int i = 0; i < model.getRowCount() - 1; i++) {
for (int j = 0; j < model.getColumnCount(); j++) {
@ -62,7 +62,7 @@ public class EvalResultLatexExport {
if (model.getValueAt(i, 0) != "") {
doc.deleteCharAt(doc.lastIndexOf(split));
}
doc.append("\\\\" + "\r\n");
doc.append("\\\\\\hline" + "\r\n");
}
doc.append("\\end{tabular}");
return doc.toString();