diff --git a/Main/pom.xml b/Main/pom.xml index 19c0ef1e9..48e6dace0 100644 --- a/Main/pom.xml +++ b/Main/pom.xml @@ -19,6 +19,9 @@ + + UTF-8 + @@ -28,74 +31,132 @@ - + io.javalin javalin 3.4.1 + + - org.json json - RELEASE + 20190722 + + - org.slf4j slf4j-simple 1.7.26 + + - - edu.wpi.first.cscore - cscore-java - RELEASE - - - - edu.wpi.first.cscore - cscore-jni - RELEASE - all - - - - edu.wpi.first.cameraserver - cameraserver-java - RELEASE - - - - edu.wpi.first.ntcore - ntcore-java - RELEASE - - - - edu.wpi.first.ntcore - ntcore-jni - RELEASE - all - - - - edu.wpi.first.wpiutil - wpiutil-java - RELEASE - - - org.apache.commons commons-math3 - RELEASE + 3.6.1 + - com.google.code.gson gson - RELEASE + 2.8.5 + + + org.springframework + spring-beans + 5.1.9.RELEASE + + + + + + edu.wpi.first.cscore + cscore-java + 2019.4.1 + + + + edu.wpi.first.cscore + cscore-jni + 2019.4.1 + linuxathena + + + edu.wpi.first.cscore + cscore-jni + 2019.4.1 + linuxraspbian + + + edu.wpi.first.cscore + cscore-jni + 2019.4.1 + linuxx86-64 + + + edu.wpi.first.cscore + cscore-jni + 2019.4.1 + windowsx86-64 + + + + + edu.wpi.first.cameraserver + cameraserver-java + 2019.4.1 + + + + + edu.wpi.first.ntcore + ntcore-java + 2019.4.1 + + + + + edu.wpi.first.ntcore + ntcore-jni + 2019.4.1 + linuxathena + + + edu.wpi.first.ntcore + ntcore-jni + 2019.4.1 + linuxraspbian + + + edu.wpi.first.ntcore + ntcore-jni + 2019.4.1 + linuxx86-64 + + + edu.wpi.first.ntcore + ntcore-jni + 2019.4.1 + windowsx86-64 + + + + + edu.wpi.first.wpiutil + wpiutil-java + 2019.4.1 + + + edu.wpi.first.thirdparty.frc2019.opencv opencv-java @@ -106,7 +167,8 @@ opencv-jni 3.4.4-5 windowsx86-64 - + + edu.wpi.first.thirdparty.frc2019.opencv opencv-jni 3.4.4-5 @@ -124,10 +186,5 @@ 3.4.4-5 linuxraspbian - - org.springframework - spring-beans - 5.1.9.RELEASE - diff --git a/Main/src/main/java/com/chameleonvision/MemoryManager.java b/Main/src/main/java/com/chameleonvision/MemoryManager.java new file mode 100644 index 000000000..881789dfd --- /dev/null +++ b/Main/src/main/java/com/chameleonvision/MemoryManager.java @@ -0,0 +1,41 @@ +package com.chameleonvision; + +public class MemoryManager { + + private static final long MEGABYTE_FACTOR = 1024L * 1024L; + + private int collectionThreshold; + private int lastUsedMb = 0; + + public MemoryManager(int collectionThreshold) { + this.collectionThreshold = collectionThreshold; + } + + + public static long getUsedMemory() { + return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); + } + + public static int getUsedMemoryMB() { + return (int) (getUsedMemory() / MEGABYTE_FACTOR); + } + + private static void collect() { + System.gc(); + System.runFinalization(); + } + + public void run() { + var usedMem = getUsedMemoryMB(); + + if (usedMem != lastUsedMb) { + lastUsedMb = usedMem; + System.out.printf("Memory usage: %dMB\n", usedMem); + } + + if (usedMem >= collectionThreshold) { + collect(); + System.out.printf("Garbage collected at %dMB\n", usedMem); + } + } +} diff --git a/Main/src/main/java/com/chameleonvision/vision/Camera.java b/Main/src/main/java/com/chameleonvision/vision/Camera.java index d64bf4cb5..fde8e0326 100644 --- a/Main/src/main/java/com/chameleonvision/vision/Camera.java +++ b/Main/src/main/java/com/chameleonvision/vision/Camera.java @@ -8,5 +8,4 @@ public class Camera { public HashMap pipelines; public int resolution = 0; public CamVideoMode camVideoMode; - } diff --git a/Main/src/main/java/com/chameleonvision/vision/process/VisionProcess.java b/Main/src/main/java/com/chameleonvision/vision/process/VisionProcess.java index ea4d9c18f..79e41c727 100644 --- a/Main/src/main/java/com/chameleonvision/vision/process/VisionProcess.java +++ b/Main/src/main/java/com/chameleonvision/vision/process/VisionProcess.java @@ -9,42 +9,53 @@ import java.util.HashMap; import java.util.List; public class VisionProcess { - private HashMapTargetGrouping= new HashMap(){{ - put("Single",1); - put("Dual",2); - put("Triple",3); - put("Quadruple",4); - put("Quintuple",5); + + private HashMapTargetGrouping= new HashMap<>() {{ + put("Single", 1); + put("Dual", 2); + put("Triple", 3); + put("Quadruple", 4); + put("Quintuple", 5); }}; - private double CamArea,CenterX, CenterY; + + private double CamArea, CenterX, CenterY; + VisionProcess(double CenterX, double CenterY, double CamArea){ this.CenterX = CenterX; this.CenterY = CenterY; this.CamArea = CamArea; } + private Mat Kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5, 5)); - public Mat HSVThreshold(@NotNull List hue, @NotNull List saturation , @NotNull List value, Mat image, boolean IsErode, boolean IsDilate){ - Mat hsv = new Mat(); - Imgproc.cvtColor(image,hsv,Imgproc.COLOR_BGR2HSV,3); - new Scalar(hue.get(0),saturation.get(0),value.get(0)); - Mat threshold = new Mat(); - Core.inRange(hsv,new Scalar(hue.get(0),saturation.get(0),value.get(0)),new Scalar(hue.get(1),saturation.get(1),value.get(1)),threshold); + private Mat hsvMat = new Mat(); + private Mat hsvThreshMat = new Mat(); + private Scalar hsvLower, hsvUpper; + + Mat HSVThreshold(@NotNull List hue, @NotNull List saturation, @NotNull List value, Mat image, boolean IsErode, boolean IsDilate){ + Imgproc.cvtColor(image, hsvMat,Imgproc.COLOR_BGR2HSV,3); + hsvLower = new Scalar(hue.get(0), saturation.get(0), value.get(0)); + hsvUpper = new Scalar(hue.get(1), saturation.get(1), value.get(1)); + Core.inRange(hsvMat, hsvLower, hsvUpper, hsvThreshMat); if (IsErode){ - Imgproc.erode(threshold,threshold, Kernel); + Imgproc.erode(hsvThreshMat, hsvThreshMat, Kernel); } if (IsDilate){ - Imgproc.dilate(threshold,threshold, Kernel); + Imgproc.dilate(hsvThreshMat, hsvThreshMat, Kernel); } - return threshold; + return hsvThreshMat; } + + private List FoundContours = new ArrayList<>(); public List FindContours(Mat BinaryImage){ - List Contours = new ArrayList<>(); - Imgproc.findContours(BinaryImage,Contours,new Mat(),Imgproc.RETR_EXTERNAL,Imgproc.CHAIN_APPROX_TC89_L1); - return Contours; + FoundContours.clear(); + Imgproc.findContours(BinaryImage, FoundContours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_TC89_L1); + BinaryImage.release(); + return FoundContours; } - public List FilterContours(List InputContours, List area, List ratio, List extent, String SortMode,String TargetIntersection , String TargetGrouping){ - List FilteredContours = new ArrayList(); + + private List FilteredContours = new ArrayList(); + public List FilterContours(List InputContours, List area, List ratio, List extent, String SortMode, String TargetIntersection, String TargetGrouping){ for (MatOfPoint Contour : InputContours){ try{ var contourArea = Imgproc.contourArea(Contour); @@ -62,24 +73,29 @@ public class VisionProcess { continue; } FilteredContours.add(Contour); - } catch (Exception e){ - continue; + } + catch (Exception e) { + } } return FilteredContours; } - private List GroupTargets(List InputContours, String IntersectionPoint,String TargetGroup){ + + private List FinalCountours = new ArrayList<>(); + private List GroupTargets(List InputContours, String IntersectionPoint,String TargetGroup) { + FinalCountours.clear(); if (!TargetGroup.equals("Single")){ - List FinalCountours = new ArrayList(); for (var i = 0; i < InputContours.size(); i++){ var FinalContour = InputContours.get(i); for (var c = 0; c < (TargetGrouping.get(TargetGroup)-1);c++){ try{ MatOfPoint firstContour = InputContours.get(i + c); - MatOfPoint secoundContour = InputContours.get(i+c+1); - if (IsIntersecting(firstContour,secoundContour, IntersectionPoint)){ + MatOfPoint secondContour = InputContours.get(i+c+1); + if (IsIntersecting(firstContour, secondContour, IntersectionPoint)){ System.out.println(""); } + firstContour.release(); + secondContour.release(); } catch (IndexOutOfBoundsException e){ FinalContour = new MatOfPoint(); break; @@ -90,12 +106,13 @@ public class VisionProcess { } return InputContours; } - private boolean IsIntersecting(MatOfPoint ContourOne, MatOfPoint ContourTwo, String IntersectionPoint){ - Mat LineA = new Mat(); - Imgproc.fitLine(ContourOne,LineA,Imgproc.CV_DIST_L2,0,0.01,0.01); - Mat LineB = new Mat(); - Imgproc.fitLine(ContourTwo,LineB,Imgproc.CV_DIST_L2,0,0.01,0.01); + + private Mat intersectMatA = new Mat(); + private Mat intersectMatB = new Mat(); + private boolean IsIntersecting(MatOfPoint ContourOne, MatOfPoint ContourTwo, String IntersectionPoint) { + Imgproc.fitLine(ContourOne, intersectMatA, Imgproc.CV_DIST_L2,0,0.01,0.01); + Imgproc.fitLine(ContourTwo, intersectMatB, Imgproc.CV_DIST_L2,0,0.01,0.01); +// Rect2d = return true; } - }