mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Fix pipeline errors
This commit is contained in:
@@ -35,6 +35,9 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
if (cameraProcess == null) {
|
||||
throw new RuntimeException("Pipeline was not initialized before being run!");
|
||||
}
|
||||
if(inputMat.cols() <= 1) {
|
||||
throw new RuntimeException("uwu uwu ");
|
||||
}
|
||||
|
||||
long totalProcessTimeNanos = 0;
|
||||
StringBuilder procTimeStringBuilder = new StringBuilder();
|
||||
|
||||
@@ -7,6 +7,7 @@ public class BlurPipe implements Pipe<Mat, Mat> {
|
||||
|
||||
private final int blurSize;
|
||||
|
||||
private Mat processBuffer = new Mat();
|
||||
private Mat outputMat = new Mat();
|
||||
|
||||
public BlurPipe(int blurSize) {
|
||||
@@ -17,13 +18,18 @@ public class BlurPipe implements Pipe<Mat, Mat> {
|
||||
public Pair<Mat, Long> run(Mat input) {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
// TODO (HIGH) make this blur
|
||||
input.copyTo(processBuffer);
|
||||
// if (blurSize > 0) {
|
||||
// Imgproc.blur(outputMat, outputMat, new Size(blurSize, blurSize));
|
||||
// }
|
||||
|
||||
processBuffer.copyTo(outputMat);
|
||||
|
||||
long processTime = processStartNanos - System.nanoTime();
|
||||
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
|
||||
outputMat.release();
|
||||
processBuffer.release();
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ public class ErodeDilatePipe implements Pipe<Mat, Mat> {
|
||||
private final boolean erode, dilate;
|
||||
private final Mat kernel;
|
||||
|
||||
private Mat processBuffer = new Mat();
|
||||
private Mat outputMat = new Mat();
|
||||
|
||||
public ErodeDilatePipe(boolean erode, boolean dilate, int kernelSize) {
|
||||
@@ -23,16 +24,22 @@ public class ErodeDilatePipe implements Pipe<Mat, Mat> {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
if (erode) {
|
||||
Imgproc.erode(outputMat, outputMat, kernel);
|
||||
Imgproc.erode(input, processBuffer, kernel);
|
||||
}
|
||||
|
||||
if (dilate) {
|
||||
Imgproc.erode(outputMat, outputMat, kernel);
|
||||
Imgproc.erode(processBuffer, processBuffer, kernel);
|
||||
}
|
||||
|
||||
if(!erode && !dilate) {
|
||||
input.copyTo(processBuffer);
|
||||
}
|
||||
|
||||
long processTime = processStartNanos - System.nanoTime();
|
||||
processBuffer.copyTo(outputMat);
|
||||
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
|
||||
outputMat.release();
|
||||
|
||||
processBuffer.release();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ public class HsvPipe implements Pipe<Mat, Mat> {
|
||||
|
||||
private final Scalar hsvLower, hsvUpper;
|
||||
|
||||
private Mat processBuffer = new Mat();
|
||||
private Mat outputMat = new Mat();
|
||||
|
||||
public HsvPipe(Scalar hsvLower, Scalar hsvUpper) {
|
||||
@@ -21,13 +22,18 @@ public class HsvPipe implements Pipe<Mat, Mat> {
|
||||
public Pair<Mat, Long> run(Mat input) {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
Imgproc.cvtColor(input, outputMat, Imgproc.COLOR_RGB2HSV, 3);
|
||||
// convert from rgb to hsv
|
||||
if(input.empty()) {
|
||||
throw new RuntimeException("HSV input cannot be empty!");
|
||||
}
|
||||
Imgproc.cvtColor(input, processBuffer, Imgproc.COLOR_RGB2HSV, 3);
|
||||
|
||||
Core.inRange(outputMat, hsvLower, hsvUpper, outputMat);
|
||||
Core.inRange(processBuffer, hsvLower, hsvUpper, processBuffer);
|
||||
|
||||
long processTime = processStartNanos - System.nanoTime();
|
||||
processBuffer.copyTo(outputMat);
|
||||
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
|
||||
outputMat.release();
|
||||
processBuffer.release();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class RotateFlipPipe implements Pipe<Mat, Mat> {
|
||||
private final ImageRotation rotation;
|
||||
private final ImageFlipMode flip;
|
||||
|
||||
private Mat processBuffer = new Mat();
|
||||
private Mat outputMat = new Mat();
|
||||
|
||||
public RotateFlipPipe(ImageRotation rotation, ImageFlipMode flip) {
|
||||
@@ -22,12 +23,13 @@ public class RotateFlipPipe implements Pipe<Mat, Mat> {
|
||||
public Pair<Mat, Long> run(Mat input) {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
Core.flip(input, outputMat, flip.value);
|
||||
Core.rotate(outputMat, outputMat, rotation.value);
|
||||
Core.flip(input, processBuffer, flip.value);
|
||||
Core.rotate(processBuffer, processBuffer, rotation.value);
|
||||
|
||||
long processTime = processStartNanos - System.nanoTime();
|
||||
processBuffer.copyTo(outputMat);
|
||||
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
|
||||
outputMat.release();
|
||||
processBuffer.release();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user