Skip to content

Commit

Permalink
Fix null pointer exception when tesseract do work with computed zones
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeybesse committed Jun 20, 2017
1 parent ec34e5e commit bd1ba9a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Expand Up @@ -3,13 +3,13 @@
import java.io.File;
import java.util.stream.Stream;

import javafx.scene.layout.GridPane;

import org.opencv.core.Core;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;

import javafx.scene.layout.GridPane;

public class ClassImgFieldsDetector extends AbstractApp {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Expand All @@ -30,8 +30,6 @@ protected void fillGrid(GridPane mainGrid) {
mainGrid.add(imgClass.getMean().getImageView(), columnIndex, rowIndex++);
mainGrid.add(imgClass.getVariance().getImageView(), columnIndex, rowIndex++);

// imgClass.addMapper(img -> img.eraseCorners(0.1).dilateBlacks(86, 255,
// 76, new Size(20, 3)));
// mainGrid.add(imgClass.getMean().getImageView(), columnIndex,
// rowIndex++);
// mainGrid.add(imgClass.getVariance().getImageView(), columnIndex,
Expand All @@ -54,6 +52,7 @@ protected void fillGrid(GridPane mainGrid) {
zones = Zones.load(imgClassDirectory);
} catch (RuntimeException e) {
System.out.println("could not load accurate zones");
imgClass.addMapper(img -> img.eraseCorners(0.1).dilateBlacks(86, 255, 76, new Size(20, 3)));
zones = Zones.get(imgClass.getClosedVarianceZones(new Size(9, 10)), 300, 6, 6);
}
Img model = imgClass.getMean();
Expand All @@ -65,7 +64,6 @@ protected void fillGrid(GridPane mainGrid) {
System.out.println("File : " + file.getName());
if (i++ > 3)
continue;
// System.out.println("File : " + file.getName());
Img img = new Img(Imgcodecs.imread(file.getPath()));
for (Zone zone : zones) {
System.out.println("Zone n°" + zone.getNum());
Expand All @@ -84,4 +82,3 @@ protected void fillGrid(GridPane mainGrid) {
}
}
}

2 changes: 1 addition & 1 deletion gs-cv/src/main/java/org/genericsystem/cv/Img.java
Expand Up @@ -430,7 +430,7 @@ public Img otsuInv() {
}

public Img dilateBlacks(double valueThreshold, double saturatioThreshold, double blueThreshold, Size dilatation) {
return range(new Scalar(0, 0, 0), new Scalar(255, saturatioThreshold, valueThreshold), true).range(new Scalar(0, 0, 0), new Scalar(blueThreshold, 255, 255), false).gray().morphologyEx(Imgproc.MORPH_DILATE, Imgproc.MORPH_RECT, dilatation);
return range(new Scalar(0, 0, 0), new Scalar(255, saturatioThreshold, valueThreshold), true).range(new Scalar(0, 0, 0), new Scalar(blueThreshold, 255, 255), false).morphologyEx(Imgproc.MORPH_DILATE, Imgproc.MORPH_RECT, dilatation);
}

public Img equalizeHisto() {
Expand Down
1 change: 0 additions & 1 deletion gs-cv/src/main/java/org/genericsystem/cv/Zones.java
Expand Up @@ -117,7 +117,6 @@ public static Zones load(File file) {
try {
return mapper.readValue(file, Zones.class);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit bd1ba9a

Please sign in to comment.