mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
changed all double and int data type to Number
added pipeline change handle in ui
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
package com.chameleonvision.util;
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
import edu.wpi.first.wpiutil.math.Num;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
public class MathHandler {
|
||||
MathHandler() {}
|
||||
|
||||
public static double sigmoid(double x){
|
||||
public static double sigmoid(Number x){
|
||||
double bias = 0;
|
||||
double a = 5;
|
||||
double b = -0.05;
|
||||
double k = 200;
|
||||
|
||||
if (x < 50){
|
||||
if (x.doubleValue() < 50){
|
||||
bias = -1.338;
|
||||
}
|
||||
|
||||
return ((k / (1 + Math.pow(Math.E,(a + (b * x))))) + bias);
|
||||
return ((k / (1 + Math.pow(Math.E,(a + (b * x.doubleValue()))))) + bias);
|
||||
}
|
||||
public static double toSlope(double angle){
|
||||
return FastMath.atan(FastMath.toRadians(angle - 90));
|
||||
|
||||
public static double toSlope(Number angle){
|
||||
return FastMath.atan(FastMath.toRadians(angle.doubleValue() - 90));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ public class Pipeline {
|
||||
public int exposure = 50;
|
||||
public int brightness = 50;
|
||||
public Orientation orientation = Orientation.Normal;
|
||||
public List<Integer> hue = Arrays.asList(50, 180);
|
||||
public List<Integer> saturation = Arrays.asList(50, 255);
|
||||
public List<Integer> value = Arrays.asList(50, 255);
|
||||
public List<Number> hue = Arrays.asList(50, 180);
|
||||
public List<Number> saturation = Arrays.asList(50, 255);
|
||||
public List<Number> value = Arrays.asList(50, 255);
|
||||
public boolean erode = false;
|
||||
public boolean dilate = false;
|
||||
public List<Float> area = Arrays.asList(0f, 100f);
|
||||
public List<Float> ratio = Arrays.asList(0f, 20f);
|
||||
public List<Integer> extent = Arrays.asList(0, 100);
|
||||
public List<Number> area = Arrays.asList(0.0, 100.0);
|
||||
public List<Number> ratio = Arrays.asList(0.0, 20.0);
|
||||
public List<Number> extent = Arrays.asList(0, 100);
|
||||
public boolean isBinary = false;
|
||||
public SortMode sortMode = SortMode.Largest;
|
||||
public TargetGroup targetGroup = TargetGroup.Single;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CVProcess {
|
||||
return foundContours;
|
||||
}
|
||||
|
||||
List<MatOfPoint> filterContours(List<MatOfPoint> inputContours, List<Float> area, List<Float> ratio, List<Integer> extent) {
|
||||
List<MatOfPoint> filterContours(List<MatOfPoint> inputContours, List<Number> area, List<Number> ratio, List<Number> extent) {
|
||||
for (MatOfPoint Contour : inputContours) {
|
||||
try {
|
||||
double contourArea = Imgproc.contourArea(Contour);
|
||||
@@ -67,14 +67,14 @@ public class CVProcess {
|
||||
var rect = Imgproc.minAreaRect(new MatOfPoint2f(Contour.toArray()));
|
||||
|
||||
var targetFullness = contourArea;
|
||||
double minExtent = (double) (extent.get(0) * rect.size.area()) / 100;
|
||||
double maxExtent = (double) (extent.get(1) * rect.size.area()) / 100;
|
||||
double minExtent = (double) (extent.get(0).doubleValue() * rect.size.area()) / 100;
|
||||
double maxExtent = (double) (extent.get(1).doubleValue() * rect.size.area()) / 100;
|
||||
if (targetFullness <= minExtent || contourArea >= maxExtent) {
|
||||
continue;
|
||||
}
|
||||
Rect bb = Imgproc.boundingRect(Contour);
|
||||
double aspectRatio = (bb.width / bb.height);
|
||||
if (aspectRatio < ratio.get(0) || aspectRatio > ratio.get(1)) {
|
||||
if (aspectRatio < ratio.get(0).doubleValue() || aspectRatio > ratio.get(1).doubleValue()) {
|
||||
continue;
|
||||
}
|
||||
filteredContours.add(Contour);
|
||||
|
||||
@@ -143,8 +143,8 @@ public class VisionProcess implements Runnable {
|
||||
inputImage.copyTo(outputImage);
|
||||
return pipelineResult;
|
||||
}
|
||||
Scalar hsvLower = new Scalar(currentPipeline.hue.get(0), currentPipeline.saturation.get(0), currentPipeline.value.get(0));
|
||||
Scalar hsvUpper = new Scalar(currentPipeline.hue.get(1), currentPipeline.saturation.get(1), currentPipeline.value.get(1));
|
||||
Scalar hsvLower = new Scalar(currentPipeline.hue.get(0).intValue(), currentPipeline.saturation.get(0).intValue(), currentPipeline.value.get(0).intValue());
|
||||
Scalar hsvUpper = new Scalar(currentPipeline.hue.get(1).intValue(), currentPipeline.saturation.get(1).intValue(), currentPipeline.value.get(1).intValue());
|
||||
|
||||
cvProcess.hsvThreshold(inputImage, hsvThreshMat, hsvLower, hsvUpper, currentPipeline.erode, currentPipeline.dilate);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
@@ -71,13 +72,21 @@ public class ServerHandler {
|
||||
case "currentPipeline": {
|
||||
CameraManager.getCurrentCamera().setCurrentPipelineIndex((Integer) entry.getValue());
|
||||
HashMap<String,Object> tmp = new HashMap<>();
|
||||
tmp.put("pipeline",CameraManager.getCurrentCamera().getCurrentPipeline());
|
||||
tmp.put("pipeline",getOrdinalPipeline());
|
||||
//TODO Add cam settings to the map
|
||||
broadcastMessage(tmp);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
setField(CameraManager.getCurrentCamera().getCurrentPipeline(),entry.getKey(),entry.getValue());
|
||||
switch (entry.getKey()){
|
||||
case "exposure":{
|
||||
CameraManager.getCurrentCamera().setExposure((Integer) entry.getValue());
|
||||
}
|
||||
case "brightness":{
|
||||
CameraManager.getCurrentCamera().setBrightness((Integer) entry.getValue());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +106,8 @@ public class ServerHandler {
|
||||
field.set(obj,value);
|
||||
}
|
||||
} else if(field.getType() == List.class){
|
||||
field.set(obj,value);
|
||||
// if(((ParameterizedType)field.getGenericType()).getActualTypeArguments()[0] == Double.class){
|
||||
field.set(obj,value);
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user