mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Added enums, msgpack - new ui intergration
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.chameleonvision.vision.process;
|
||||
|
||||
import com.chameleonvision.vision.SortMode;
|
||||
import com.chameleonvision.vision.TargetGroup;
|
||||
import com.chameleonvision.vision.TargetIntersection;
|
||||
import com.chameleonvision.vision.camera.CameraValues;
|
||||
import com.chameleonvision.util.MathHandler;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
@@ -14,13 +17,6 @@ import java.util.*;
|
||||
public class CVProcess {
|
||||
|
||||
private final CameraValues cameraValues;
|
||||
private HashMap<String, Integer> targetGrouping = new HashMap<>() {{
|
||||
put("Single", 1);
|
||||
put("Dual", 2);
|
||||
put("Triple", 3);
|
||||
put("Quadruple", 4);
|
||||
put("Quintuple", 5);
|
||||
}};
|
||||
private Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5, 5));
|
||||
private Size blur = new Size(1,1);
|
||||
private Mat hsvImage = new Mat();
|
||||
@@ -58,7 +54,7 @@ public class CVProcess {
|
||||
return foundContours;
|
||||
}
|
||||
|
||||
List<MatOfPoint> filterContours(List<MatOfPoint> inputContours, List<Integer> area, List<Double> ratio, List<Integer> extent) {
|
||||
List<MatOfPoint> filterContours(List<MatOfPoint> inputContours, List<Float> area, List<Float> ratio, List<Integer> extent) {
|
||||
for (MatOfPoint Contour : inputContours) {
|
||||
try {
|
||||
double contourArea = Imgproc.contourArea(Contour);
|
||||
@@ -97,34 +93,34 @@ public class CVProcess {
|
||||
Moments m = Imgproc.moments(c);
|
||||
return (m.get_m10()/m.get_m00());
|
||||
}
|
||||
RotatedRect sortTargetsToOne(List<RotatedRect> inputRects, String sortMode) {
|
||||
RotatedRect sortTargetsToOne(List<RotatedRect> inputRects, SortMode sortMode) {
|
||||
switch (sortMode) {
|
||||
case "Largest":
|
||||
case Largest:
|
||||
return Collections.max(inputRects, Comparator.comparing(rect -> rect.size.area()));
|
||||
case "Smallest":
|
||||
case Smallest:
|
||||
return Collections.min(inputRects, Comparator.comparing(rect -> rect.size.area()));
|
||||
case "Highest":
|
||||
case Highest:
|
||||
return Collections.min(inputRects, Comparator.comparing(rect -> rect.center.y));
|
||||
case "Lowest":
|
||||
case Lowest:
|
||||
return Collections.max(inputRects, Comparator.comparing(rect -> rect.center.y));
|
||||
case "Leftmost":
|
||||
case Leftmost:
|
||||
return Collections.min(inputRects, Comparator.comparing(rect -> rect.center.x));
|
||||
case "Rightmost":
|
||||
case Rightmost:
|
||||
return Collections.max(inputRects, Comparator.comparing(rect -> rect.center.x));
|
||||
case "Centermost":
|
||||
case Centermost:
|
||||
return Collections.min(inputRects, sortByCentermostComparator);
|
||||
default:
|
||||
return inputRects.get(0); // default to whatever the first contour is, but this should never happen
|
||||
}
|
||||
}
|
||||
|
||||
List<RotatedRect> groupTargets(List<MatOfPoint> inputContours, String intersectionPoint, String targetGroup) {
|
||||
List<RotatedRect> groupTargets(List<MatOfPoint> inputContours, TargetIntersection intersectionPoint, TargetGroup targetGroup) {
|
||||
finalCountours.clear();
|
||||
if (!targetGroup.equals("Single")) {
|
||||
if (!targetGroup.equals(TargetGroup.Single)) {
|
||||
inputContours.sort(sortByMomentsX);
|
||||
for (var i = 0; i < inputContours.size(); i++) {
|
||||
List<Point> FinalContourList = new ArrayList<>(inputContours.get(i).toList());
|
||||
for (var c = 0; c < (targetGrouping.get(targetGroup) - 1); c++) {
|
||||
for (var c = 0; c < targetGroup.ordinal(); c++) {
|
||||
try {
|
||||
MatOfPoint firstContour = inputContours.get(i + c);
|
||||
MatOfPoint secondContour = inputContours.get(i + c + 1);
|
||||
@@ -163,8 +159,8 @@ public class CVProcess {
|
||||
return finalCountours;
|
||||
}
|
||||
|
||||
private boolean isIntersecting(MatOfPoint ContourOne, MatOfPoint ContourTwo, String IntersectionPoint) {
|
||||
if (IntersectionPoint.equals("None")) {
|
||||
private boolean isIntersecting(MatOfPoint ContourOne, MatOfPoint ContourTwo, TargetIntersection intersectionPoint) {
|
||||
if (intersectionPoint.equals(TargetIntersection.None)) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
@@ -182,26 +178,26 @@ public class CVProcess {
|
||||
double intersectionY = (mA * (intersectionX - x0A)) + y0A;
|
||||
double massX = (x0A + x0B) / 2;
|
||||
double massY = (y0A + y0B) / 2;
|
||||
switch (IntersectionPoint) {
|
||||
case "Up": {
|
||||
switch (intersectionPoint) {
|
||||
case Up: {
|
||||
if (intersectionY < massY) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Down": {
|
||||
case Down: {
|
||||
if (intersectionY > massY) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Left": {
|
||||
case Left: {
|
||||
if (intersectionX < massX) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Right": {
|
||||
case Right: {
|
||||
if (intersectionX > massX) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.chameleonvision.vision.process;
|
||||
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
import com.chameleonvision.vision.Orientation;
|
||||
import com.chameleonvision.vision.Pipeline;
|
||||
import com.chameleonvision.vision.camera.Camera;
|
||||
import com.chameleonvision.web.ServerHandler;
|
||||
@@ -135,7 +136,7 @@ public class VisionProcess implements Runnable {
|
||||
if (currentPipeline == null) {
|
||||
return pipelineResult;
|
||||
}
|
||||
if (!currentPipeline.orientation.equals("Normal")) {
|
||||
if (currentPipeline.orientation.equals(Orientation.Inverted)) {
|
||||
Core.flip(inputImage, inputImage, -1);
|
||||
}
|
||||
if (ntDriverModeEntry.getBoolean(false)) {
|
||||
@@ -147,7 +148,7 @@ public class VisionProcess implements Runnable {
|
||||
|
||||
cvProcess.hsvThreshold(inputImage, hsvThreshMat, hsvLower, hsvUpper, currentPipeline.erode, currentPipeline.dilate);
|
||||
|
||||
if (currentPipeline.is_binary == 1) {
|
||||
if (currentPipeline.isBinary == true) {
|
||||
Imgproc.cvtColor(hsvThreshMat, outputImage, Imgproc.COLOR_GRAY2BGR, 3);
|
||||
} else {
|
||||
inputImage.copyTo(outputImage);
|
||||
@@ -156,13 +157,13 @@ public class VisionProcess implements Runnable {
|
||||
if (foundContours.size() > 0) {
|
||||
filteredContours = cvProcess.filterContours(foundContours, currentPipeline.area, currentPipeline.ratio, currentPipeline.extent);
|
||||
if (filteredContours.size() > 0) {
|
||||
groupedContours = cvProcess.groupTargets(filteredContours, currentPipeline.target_intersection, currentPipeline.target_group);
|
||||
groupedContours = cvProcess.groupTargets(filteredContours, currentPipeline.targetIntersection, currentPipeline.targetGroup);
|
||||
if (groupedContours.size() > 0) {
|
||||
var finalRect = cvProcess.sortTargetsToOne(groupedContours, currentPipeline.sort_mode);
|
||||
var finalRect = cvProcess.sortTargetsToOne(groupedContours, currentPipeline.sortMode);
|
||||
// System.out.printf("Largest Contour Area: %.2f\n", finalRect.size.area());
|
||||
pipelineResult.RawPoint = finalRect;
|
||||
pipelineResult.IsValid = true;
|
||||
if (!currentPipeline.is_calibrated) {
|
||||
if (!currentPipeline.isCalibrated) {
|
||||
pipelineResult.CalibratedX = camera.getCamVals().CenterX;
|
||||
pipelineResult.CalibratedY = camera.getCamVals().CenterY;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user