Fix CvExceptions for pipes, CVPipeline2d cleanups

This commit is contained in:
Banks Troutman
2019-11-24 21:07:22 -05:00
parent 88cfbc820a
commit 4975e5cfe8
5 changed files with 21 additions and 17 deletions

View File

@@ -44,9 +44,9 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
public void initPipeline(CameraProcess process) {
super.initPipeline(process);
var camProps = cameraProcess.getProperties().staticProperties;
var hsvLower = new Scalar(settings.hue.get(0).intValue(), settings.saturation.get(0).intValue(), settings.value.get(0).intValue());
var hsvUpper = new Scalar(settings.hue.get(1).intValue(), settings.saturation.get(1).intValue(), settings.value.get(1).intValue());
CameraStaticProperties camProps = cameraProcess.getProperties().staticProperties;
Scalar hsvLower = new Scalar(settings.hue.get(0).intValue(), settings.saturation.get(0).intValue(), settings.value.get(0).intValue());
Scalar hsvUpper = new Scalar(settings.hue.get(1).intValue(), settings.saturation.get(1).intValue(), settings.value.get(1).intValue());
rotateFlipPipe = new RotateFlipPipe(ImageRotation.DEG_0, settings.flipMode);
blurPipe = new BlurPipe(5);
@@ -70,7 +70,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
throw new RuntimeException("Pipeline was not initialized before being run!");
}
if(inputMat.cols() <= 1) {
throw new RuntimeException("uwu uwu ");
throw new RuntimeException("Input Mat is empty!");
}
StringBuilder procTimeStringBuilder = new StringBuilder();
@@ -79,10 +79,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
inputMat.copyTo(rawCameraMat);
// rawCameraMat = inputMat;
// prepare pipes
Scalar hsvLower = new Scalar(settings.hue.get(0).intValue(), settings.saturation.get(0).intValue(), settings.value.get(0).intValue());
Scalar hsvUpper = new Scalar(settings.hue.get(1).intValue(), settings.saturation.get(1).intValue(), settings.value.get(1).intValue());

View File

@@ -25,15 +25,18 @@ public class BlurPipe implements Pipe<Mat, Mat> {
public Pair<Mat, Long> run(Mat input) {
long processStartNanos = System.nanoTime();
input.copyTo(processBuffer);
try {
if (blurSize > 0) {
Imgproc.blur(outputMat, outputMat, new Size(blurSize, blurSize));
Imgproc.blur(processBuffer, processBuffer, new Size(blurSize, blurSize));
}
} catch (CvException e) {
System.err.println("(BlurPipe) Exception thrown by OpenCV: \n" + e.getMessage());
}
long processTime = System.nanoTime() - processStartNanos;
processBuffer.copyTo(outputMat);
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
processBuffer.release();

View File

@@ -30,21 +30,19 @@ public class ErodeDilatePipe implements Pipe<Mat, Mat> {
public Pair<Mat, Long> run(Mat input) {
long processStartNanos = System.nanoTime();
input.copyTo(processBuffer);
if (erode) {
Imgproc.erode(input, processBuffer, kernel);
Imgproc.erode(processBuffer, processBuffer, kernel);
}
if (dilate) {
Imgproc.erode(processBuffer, processBuffer, kernel);
}
if(!erode && !dilate) {
input.copyTo(processBuffer);
}
long processTime = System.nanoTime() - processStartNanos;
processBuffer.copyTo(outputMat);
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
processBuffer.release();
return output;
}

View File

@@ -29,14 +29,17 @@ public class HsvPipe implements Pipe<Mat, Mat> {
public Pair<Mat, Long> run(Mat input) {
long processStartNanos = System.nanoTime();
input.copyTo(processBuffer);
try {
Imgproc.cvtColor(input, outputMat, Imgproc.COLOR_RGB2HSV, 3);
Core.inRange(outputMat, hsvLower, hsvUpper, outputMat);
Imgproc.cvtColor(processBuffer, processBuffer, Imgproc.COLOR_RGB2HSV, 3);
Core.inRange(processBuffer, hsvLower, hsvUpper, processBuffer);
} catch (CvException e) {
System.err.println("(HsvPipe) Exception thrown by OpenCV: \n" + e.getMessage());
}
long processTime = System.nanoTime() - processStartNanos;
processBuffer.copyTo(outputMat);
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
processBuffer.release();
return output;

View File

@@ -28,10 +28,13 @@ public class RotateFlipPipe implements Pipe<Mat, Mat> {
public Pair<Mat, Long> run(Mat input) {
long processStartNanos = System.nanoTime();
Core.flip(input, processBuffer, flip.value);
input.copyTo(processBuffer);
Core.flip(processBuffer, processBuffer, flip.value);
Core.rotate(processBuffer, processBuffer, rotation.value);
long processTime = System.nanoTime() - processStartNanos;
processBuffer.copyTo(outputMat);
Pair<Mat, Long> output = Pair.of(outputMat, processTime);
processBuffer.release();
return output;