- public static void main(String args[]) throws Exception {
-
- matOriginal = new Mat();
- filtered = new Mat();
- matHierarchy = new Mat();
-
- kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3));
-
- findContours();
- }
-
- public static void findContours() {
-
- ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
- int frameCount = 0;
- int THE_BEST_MAGIC_NUMBER = 300;
-
- contours.clear();
- matOriginal = Imgcodecs.imread("imgs/goal2.png"); // convert image
- // into matrix
-
- filtered = matOriginal;
-
- Imgproc.cvtColor(matOriginal, filtered, Imgproc.COLOR_BGR2GRAY);
- // takes out unnecessary colors
-
- Imgproc.GaussianBlur(matOriginal, filtered, new Size(5, 5), Core.BORDER_DEFAULT);
-
- // bing bing bong bong
- // bing bing bong bong
-
- // converts image to grayscale, blurs it, and detects edges
-
- Imgproc.Canny(matOriginal, filtered, 35, 125);
-
- Imgproc.findContours(filtered, contours, matHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
-
- for (Iterator<MatOfPoint> iterator = contours.iterator(); iterator.hasNext();) {
- MatOfPoint matOfPoint = iterator.next();
- Rect rec = Imgproc.boundingRect(matOfPoint);
- if (rec.height < THE_BEST_MAGIC_NUMBER || rec.width < THE_BEST_MAGIC_NUMBER) {