-import java.awt.Panel;
-import java.awt.image.BufferedImage;
-
import org.opencv.core.Core;
import org.opencv.core.Mat;
+import org.opencv.core.Point;
import org.opencv.core.Scalar;
+import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
+import org.opencv.imgproc.Imgproc;
-public class IsolateImage extends Panel {
- BufferedImage filteredImage;
- BufferedImage origImage;
+public class IsolateImage {
public static Mat matOriginal;
public static Mat filtered;
+ public static Mat kernel;
- public static final Scalar LOWER_BOUNDS = new Scalar(103, 164, 169);
- public static final Scalar UPPER_BOUNDS = new Scalar(125, 229, 255);
+ 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 UPPER_BOUNDS = new Scalar(0, 255, 255);
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
- public IsolateImage() {
-
- }
-
public static void main(String args[]) throws Exception {
matOriginal = new Mat();
filtered = new Mat();
+ kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
+
processImage();
}
matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image
// into matrix
+ filtered = matOriginal;
+
Core.inRange(matOriginal, LOWER_BOUNDS, UPPER_BOUNDS, filtered);
+ Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 2);
Imgcodecs.imwrite("output.png", filtered);