+import java.util.ArrayList;
+
import org.opencv.core.Core;
import org.opencv.core.Mat;
+import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
public static Mat matOriginal;
public static Mat filtered;
public static Mat kernel;
+ public static Mat matHierarchy;
public static final Scalar LOWER_BOUNDS = new Scalar(169, 164, 103);
public static final Scalar UPPER_BOUNDS = new Scalar(255, 229, 140);
- // public static final Scalar LOWER_BOUNDS = new Scalar(255, 0, 0);
+ public static final Scalar BLACK = new Scalar(0, 0, 0);
// public static final Scalar UPPER_BOUNDS = new Scalar(0, 255, 255);
static {
matOriginal = new Mat();
filtered = new Mat();
+ matHierarchy = new Mat();
- kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
+ kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5, 5));
processImage();
}
public static void processImage() {
+ ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
+ contours.clear();
matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image
- // into matrix
+ // into matrix
filtered = matOriginal;
+ Imgproc.GaussianBlur(matOriginal, filtered, new Size(17, 17), Core.BORDER_DEFAULT);
Core.inRange(matOriginal, LOWER_BOUNDS, UPPER_BOUNDS, filtered);
- Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 2);
-
+ // Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 4);
+ Imgproc.dilate(matOriginal, filtered, kernel, new Point(-1, -1), 4);
+ // Imgproc.findContours(filtered, contours, matHierarchy,
+ // Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
+
+ // for (MatOfPoint mop : contours) {
+ // Rect rec = Imgproc.boundingRect(mop);
+ // Imgproc.rectangle(matOriginal, rec.br(), rec.tl(), BLACK, 5);
+ // }
Imgcodecs.imwrite("output.png", filtered);
}