Skip to content

Commit

Permalink
Detect blur on images
Browse files Browse the repository at this point in the history
  • Loading branch information
nfeybesse committed Jul 2, 2018
1 parent 2020bee commit f4b25a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
Expand Up @@ -37,7 +37,7 @@ public static Mat fastHoughTransform(Mat strip) {
Ximgproc.FastHoughTransform(strip, houghTransform, CvType.CV_64FC1, Ximgproc.ARO_45_135, Ximgproc.FHT_ADD, Ximgproc.HDO_DESKEW);
Core.transpose(houghTransform, houghTransform);
Core.normalize(houghTransform, houghTransform, 0, 1, Core.NORM_MINMAX);
return new Mat(houghTransform, new Range(strip.width() / 2 - 1, houghTransform.height() - strip.width() / 2 + 1), new Range(0, houghTransform.width()));
return new Mat(houghTransform, new Range(strip.width() / 2 - 1, houghTransform.height() - strip.width() / 2 - 1), new Range(0, houghTransform.width()));
}

static Mat adaptivHough(Mat houghTransform, int blurSize) {
Expand Down
Expand Up @@ -43,8 +43,8 @@ public class FHTManager {
private DoubleProperty vMaxConnectDistance = new SimpleDoubleProperty(0.05);
private DoubleProperty interpolatorPow = new SimpleDoubleProperty(4);
private DoubleProperty interpolatorMinDist = new SimpleDoubleProperty(0.0001);
private IntegerProperty halfGridWidth = new SimpleIntegerProperty(6);
private IntegerProperty halfGridHeight = new SimpleIntegerProperty(4);
private IntegerProperty halfGridWidth = new SimpleIntegerProperty(8);
private IntegerProperty halfGridHeight = new SimpleIntegerProperty(8);
private IntegerProperty optimizationsCount = new SimpleIntegerProperty(0);

private final Size binarySize;
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDouble;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
Expand Down Expand Up @@ -119,6 +120,7 @@ private Image[] doWork() {

Img binarized = frame.adaptativeGaussianInvThreshold(7, 5);
Img flat = fhtManager.init(frame.getSrc(), binarized.getSrc()).getDewarp();

images[1] = flat.toJfxImage();
ref = trace("Dewarp", ref);
// Img flatBinarized = flat.adaptativeGaussianInvThreshold(7, 5);
Expand Down Expand Up @@ -163,8 +165,18 @@ private Image[] doWork() {

Mat flatDisplay2 = Mat.zeros(flat.size(), flat.type());
Labels labels = new Labels(detectedClosedRects);
labels.ocr(flat.getSrc(), 1, 1, 2, 2);
labels.ocr(flat.getSrc(), 0, 1, 2, 2);
labels.putOcr(flatDisplay2);
Mat destination = new Mat();
Mat matGray = new Mat();
Imgproc.cvtColor(flat.getSrc(), matGray, Imgproc.COLOR_BGR2GRAY);
Imgproc.Laplacian(matGray, destination, 3);
MatOfDouble median = new MatOfDouble();
MatOfDouble std = new MatOfDouble();
Core.meanStdDev(destination, median, std);
Imgproc.putText(flatDisplay2, "Quality : " + (int) Math.pow(std.get(0, 0)[0], 2), new Point(50, 50), Core.FONT_HERSHEY_PLAIN, 1, new Scalar(0, 0, 255), 1);

System.out.println("Quality : " + Math.pow(std.get(0, 0)[0], 2));
images[4] = new Img(flatDisplay2, false).toJfxImage();
ref = trace("Ocr", ref);

Expand Down Expand Up @@ -304,7 +316,7 @@ public void putOcr(Mat img) {

if (scale < 0.3 && scale > 3)
scale = 1;
Imgproc.putText(img, normalizedText, new Point(rect.tl().x, rect.br().y), Core.FONT_HERSHEY_PLAIN, scale, new Scalar(0, 0, 255), 1);
Imgproc.putText(img, normalizedText, new Point(rect.tl().x, rect.br().y), Core.FONT_HERSHEY_PLAIN, scale, new Scalar(0, 255, 0), 1);
}

public String getLabel() {
Expand Down
@@ -1,12 +1,5 @@
package org.genericsystem.cv.application;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.genericsystem.cv.AbstractApp;
import org.genericsystem.cv.Img;
import org.genericsystem.cv.utils.NativeLibraryLoader;
Expand All @@ -19,6 +12,14 @@
import org.opencv.imgproc.Imgproc;
import org.opencv.utils.Converters;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
Expand All @@ -39,7 +40,7 @@ public static void main(String[] args) {
private ScheduledExecutorService timer = new BoundedScheduledThreadPoolExecutor();
private Config config = new Config();
private final ImageView[][] imageViews = new ImageView[][] { new ImageView[3], new ImageView[3], new ImageView[3], new ImageView[3] };
private final MSER detector = MSER.create(2, 10, 2000, 0.25, 0.2, 200, 1.01, 0.03, 5);
private final MSER detector = MSER.create(2, 10, 1000, 0.25, 0.2, 200, 1.01, 0.03, 5);

private void startTimer() {
timer.scheduleAtFixedRate(() -> {
Expand Down

0 comments on commit f4b25a3

Please sign in to comment.