added target grouping

This commit is contained in:
ori agranat
2019-09-14 20:38:50 +03:00
parent 1b8943eb27
commit d6850f73b1
5 changed files with 87 additions and 9 deletions

View File

@@ -20,15 +20,16 @@ public class CameraProcess implements Runnable{
@Override
public void run() {
//calling all classes
CameraServer cs = CameraServer.getInstance();
NetworkTableInstance networkTableInstance = NetworkTableInstance.getDefault();
// NetworkTableInstance networkTableInstance = NetworkTableInstance.getDefault();
SettingsManager manager = SettingsManager.getInstance();
VisionProcess visionProcess = new VisionProcess();
manager.CamerasCurrentPipeline.put(CameraName,manager.Cameras.get(CameraName).pipelines.keySet().toArray()[0].toString());
//Setting up camera and network table
var Table = networkTableInstance.getTable("/Chameleon-Vision/" + CameraName);
var PipeLineEntry = Table.getEntry("Pipeline");
var DriverModeEntry = Table.getEntry("Driver_Mode");
// var Table = networkTableInstance.getTable("/Chameleon-Vision/" + CameraName);
// var PipeLineEntry = Table.getEntry("Pipeline");
// var DriverModeEntry = Table.getEntry("Driver_Mode");
var cv_sink = cs.getVideo(manager.UsbCameras.get(CameraName));
int Width = manager.Cameras.get(CameraName).camVideoMode.width;
int Height = manager.Cameras.get(CameraName).camVideoMode.heigh;
@@ -42,14 +43,20 @@ public class CameraProcess implements Runnable{
double VerticalView = FastMath.atan(FastMath.tan(DiagonalView/2) * (VerticalRatio / DiagonalView)) * 2;
double H_FOCAL_LENGTH = Width / (2 * FastMath.tan(HorizontalView /2));
double V_FOCAL_LENGTH = Width / (2 * FastMath.tan(VerticalView /2));
double CenterX = ((double) Width / 2) - 0.5;
double CenterY = ((double) Height/2) - 0.5;
double CamArea = (double)(Width * Height);
VisionProcess visionProcess = new VisionProcess(CenterX,CenterY,CamArea);
Mat mat = new Mat();
long time;
while (!Thread.interrupted()){
Pipeline pipeline = manager.Cameras.get(CameraName).pipelines.get(manager.CamerasCurrentPipeline.get(CameraName));
time = cv_sink.grabFrame(mat);
Mat HSVImage = visionProcess.HSVThreshold(pipeline.hue,pipeline.saturation,pipeline.value,mat,pipeline.erode,pipeline.dilate);
List<MatOfPoint> Contours = visionProcess.FindContours(HSVImage);
// Mat HSVImage = visionProcess.HSVThreshold(pipeline.hue,pipeline.saturation,pipeline.value,mat,pipeline.erode,pipeline.dilate);
// List<MatOfPoint> Contours = visionProcess.FindContours(HSVImage);
// List<MatOfPoint> FilterdContours = visionProcess.FilterContours(Contours,pipeline.area,pipeline.ratio,pipeline.extent,pipeline.sort_mode,pipeline.target_intersection,pipeline.target_group);
cv_publish.putFrame(mat);
}
}