Colored shape fix (#288)

* Move test images out of resources folder

* Limit workers in CI

* Fix image area filtering bug in colored shape

* Add missing picam settings

* Swap to make blank/empty Mat when a picam doesn't supply a color image.

Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
Chris Gerth
2021-09-23 17:48:18 -05:00
committed by GitHub
parent 9fdd945a52
commit db09e5209f
5 changed files with 39 additions and 8 deletions

View File

@@ -40,7 +40,9 @@ public class Draw2dTargetsPipe
@Override
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
var imageSize = Math.sqrt(in.getLeft().rows() * in.getLeft().cols());
var imRows = in.getLeft().rows();
var imCols = in.getLeft().cols();
var imageSize = Math.sqrt(imRows * imCols);
var textSize = params.kPixelsToText * imageSize;
var thickness = params.kPixelsToThickness * imageSize;

View File

@@ -50,8 +50,10 @@ public class FilterShapesPipe
private boolean shouldRemove(CVShape shape) {
return shape.shape != params.desiredShape
|| shape.contour.getArea() / params.getFrameStaticProperties().imageArea > params.maxArea
|| shape.contour.getArea() / params.getFrameStaticProperties().imageArea < params.minArea
|| shape.contour.getArea() / params.getFrameStaticProperties().imageArea * 100.0
> params.maxArea
|| shape.contour.getArea() / params.getFrameStaticProperties().imageArea * 100.0
< params.minArea
|| shape.contour.getPerimeter() > params.maxPeri
|| shape.contour.getPerimeter() < params.minPeri;
}

View File

@@ -25,6 +25,7 @@ import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.raspi.PicamJNI;
import org.photonvision.vision.camera.CameraQuirk;
import org.photonvision.vision.frame.Frame;
import org.photonvision.vision.opencv.*;
import org.photonvision.vision.pipe.CVPipe.CVPipeResult;
@@ -78,6 +79,23 @@ public class ColoredShapePipeline
new RotateImagePipe.RotateImageParams(settings.inputImageRotationMode);
rotateImagePipe.setParams(rotateImageParams);
if (cameraQuirks.hasQuirk(CameraQuirk.PiCam) && PicamJNI.isSupported()) {
PicamJNI.setThresholds(
settings.hsvHue.getFirst() / 180d,
settings.hsvSaturation.getFirst() / 255d,
settings.hsvValue.getFirst() / 255d,
settings.hsvHue.getSecond() / 180d,
settings.hsvSaturation.getSecond() / 255d,
settings.hsvValue.getSecond() / 255d);
PicamJNI.setRotation(settings.inputImageRotationMode.value);
PicamJNI.setShouldCopyColor(settings.inputShouldShow);
} else {
var hsvParams =
new HSVPipe.HSVParams(settings.hsvHue, settings.hsvSaturation, settings.hsvValue);
hsvPipe.setParams(hsvParams);
}
ErodeDilatePipe.ErodeDilateParams erodeDilateParams =
new ErodeDilatePipe.ErodeDilateParams(settings.erode, settings.dilate, 5);
// TODO: add kernel size to pipeline settings
@@ -203,8 +221,8 @@ public class ColoredShapePipeline
// If we grabbed it (in color copy mode), make a new Mat of it
rawInputMat = new Mat(inputMatPtr);
} else {
// Otherwise, the input mat is frame we got from the camera
rawInputMat = frame.image.getMat();
// Otherwise, use a blank/empty mat as placeholder
rawInputMat = new Mat();
}
// We can skip a few steps if the image is single channel because we've already done them on

View File

@@ -164,8 +164,8 @@ public class ReflectivePipeline extends CVPipeline<CVPipelineResult, ReflectiveP
// If we grabbed it (in color copy mode), make a new Mat of it
rawInputMat = new Mat(inputMatPtr);
} else {
// Otherwise, the input mat is frame we got from the camera
rawInputMat = frame.image.getMat();
// Otherwise, use a blank/empty mat as placeholder
rawInputMat = new Mat();
}
// We can skip a few steps if the image is single channel because we've already done them on

View File

@@ -30,11 +30,13 @@ import org.photonvision.common.logging.LogLevel;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.networking.NetworkManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.util.numbers.IntegerCouple;
import org.photonvision.raspi.PicamJNI;
import org.photonvision.server.Server;
import org.photonvision.vision.camera.FileVisionSource;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.opencv.ContourGroupingMode;
import org.photonvision.vision.opencv.ContourShape;
import org.photonvision.vision.pipeline.CVPipelineSettings;
import org.photonvision.vision.pipeline.ColoredShapePipelineSettings;
import org.photonvision.vision.pipeline.PipelineProfiler;
@@ -130,7 +132,14 @@ public class Main {
"Shape",
TestUtils.getPowercellImagePath(TestUtils.PowercellTestImages.kPowercell_test_1, true)
.toString());
camConfShape.addPipelineSetting(new ColoredShapePipelineSettings());
var settings = new ColoredShapePipelineSettings();
settings.hsvHue = new IntegerCouple(0, 35);
settings.hsvSaturation = new IntegerCouple(82, 255);
settings.hsvValue = new IntegerCouple(62, 255);
settings.contourShape = ContourShape.Triangle;
settings.outputShowMultipleTargets = true;
settings.circleAccuracy = 15;
camConfShape.addPipelineSetting(settings);
var fvsShape = new FileVisionSource(camConfShape);
collectedSources.add(fvsShape);