anpassungen

This commit is contained in:
Armin Wolf 2017-09-19 09:40:37 +02:00
parent a3d2d97dcf
commit 813155347d
3 changed files with 27 additions and 39 deletions

View File

@ -34,33 +34,8 @@ public class LineModel {
}
public void setXbounds() {
LinkedList<Double> xlist = new LinkedList<>();
for (Point p : nodes) {
xlist.add(p.getX());
}
xMaximum = Collections.max(xlist);
xMinimum = Collections.min(xlist);
}
public void setYbounds() {
LinkedList<Double> ylist = new LinkedList<>();
for (Point p : nodes) {
ylist.add(p.getY());
}
yMaximum = Collections.max(ylist);
yMinimum = Collections.min(ylist);
}
public void addNode(Point node) {
this.nodes.add(node);
xMaximum = (node.getX() > xMaximum) ? node.getX() : xMinimum;
xMinimum = (node.getX() <= xMinimum) ? node.getX() : xMinimum;
yMaximum = (node.getY() > yMaximum) ? node.getY() : yMaximum;
yMaximum = (node.getY() <= yMaximum) ? node.getY() : yMaximum;
}
public void addLine(Line line) {

View File

@ -138,13 +138,6 @@ public abstract class AbstractPresenter implements Observer {
if (result[0] == "import-picture") {
//100% erreicht
SwingUtilities.invokeLater(() -> {
getView().enableFunctionality();
getView().logHeading("Import eines Bildes");
getView().log("Anzahl der Geraden: "+ getModel().getLines().size() + ".");
getView().log("Anzahl der Schnittpunkte: "+getModel().getNodes().size()+".");
getView().logSuccess("Der Import war Erfolgreich! <hr>");
});
Thread t = new Thread(() -> {
calculateIntersections();
@ -156,6 +149,14 @@ public abstract class AbstractPresenter implements Observer {
e.printStackTrace();
}
SwingUtilities.invokeLater(() -> {
getView().enableFunctionality();
getView().logHeading("Import eines Bildes");
getView().log("Anzahl der Geraden: "+ getModel().getLines().size() + ".");
getView().log("Anzahl der Schnittpunkte: "+getModel().getNodes().size()+".");
getView().logSuccess("Der Import war Erfolgreich! <hr>");
});
}
}

View File

@ -27,6 +27,7 @@ public class PictureProcessor extends Observable{
private Presenter presenter;
private File file;
private ArrayList<MatOfPoint> contours;
private double contourLength;
public PictureProcessor(Presenter presenter, File file) {
this.file = file;
@ -36,6 +37,7 @@ public class PictureProcessor extends Observable{
public void run(){
image = Highgui.imread(file.getAbsolutePath());
contour = process(image);
contourLength = image.width() * 0.3;
createInputData();
}
@ -43,22 +45,29 @@ public class PictureProcessor extends Observable{
Mat threshold = new Mat(image.width(), image.height(), CvType.CV_8UC1);
Mat source = new Mat(image.width(), image.height(), CvType.CV_8UC1);
Imgproc.cvtColor(image, source, Imgproc.COLOR_BGR2GRAY);
Imgproc.blur(source, threshold, new Size(3,3));
Imgproc.GaussianBlur(source, threshold, new Size(3,3),0,0);
Imgproc.Canny(threshold, source,300,600,5,true);
//Konturen berechnen und filtern
contours = new ArrayList<>();
Imgproc.findContours(source, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0,0));
Mat viscont = new Mat(source.size(), source.type());
double minArea = 50;
double maxArea = 0.2 * image.cols() * image.rows();
for (int i=0;i<contours.size();i++) {
if (Imgproc.contourArea(contours.get(i)) > 100) {
Imgproc.drawContours(viscont, contours, i, new Scalar(255, 255, 100), -1);
double acutualArea = Imgproc.contourArea(contours.get(i));
if (minArea < acutualArea && maxArea > acutualArea) {
Imgproc.drawContours(viscont, contours, i, new Scalar(255, 0, 0), 1);
}
}
Mat resized = new Mat();
Imgproc.resize(viscont, resized,new Size(560,560));
SwingUtilities.invokeLater(() -> {
JDialog dialog = new JDialog();
dialog.setSize(1100,700);
dialog.add(new JLabel(new ImageIcon(toBufferedImage(viscont))));
dialog.setSize(560,560);
JLabel label = new JLabel();
label.setSize(560,560);
label.setIcon(new ImageIcon(toBufferedImage(resized)));
dialog.add(label);
dialog.setVisible(true);
});
return source;
@ -82,10 +91,13 @@ public class PictureProcessor extends Observable{
private void createInputData(){
Thread t = new Thread(() -> {
double minArea = 50;
double maxArea = 0.2 * image.cols() * image.rows();
int id = 0;
for (int j=0;j<contours.size();j++){
Point[] p = contours.get(j).toArray();
if (p.length > 200) {
double acutualArea = Imgproc.contourArea(contours.get(j));
if (minArea < acutualArea && maxArea > acutualArea) {
for (int i = 0; i < p.length; i++) {
Line line = new Line(-1 * (500 - p[i].x), p[i].y);
line.setId("" + id++);