diff --git a/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/Main.java b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/Main.java index b0ce083..d2e95a3 100644 --- a/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/Main.java +++ b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/Main.java @@ -6,7 +6,6 @@ import org.opencv.imgcodecs.Imgcodecs; import de.unidue.nes.gpu.testframework.input.MatTuple; import de.unidue.nes.gpu.testframework.input.MatTupleInput; import de.unidue.nes.gpu.testframework.opencv.Imgproc; -import de.unidue.nes.gpu.testframework.opencv.StereoBM; import de.unidue.nes.gpu.testframework.tasks.CpuTask; import de.unidue.nes.gpu.testframework.tasks.CustomTask; import de.unidue.nes.gpu.testframework.tasks.GpuTask; @@ -26,14 +25,11 @@ public class Main { TestUtils utils = new TestUtils<>(); utils.setCommandPipeline(tupleInput -> { Mat left = tupleInput.get().left; - Mat right = tupleInput.get().right; Imgproc.cvtColor(left, left, org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY); - Imgproc.cvtColor(right, right, org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY); - StereoBM matcher = StereoBM.create(); - Mat disparity = new Mat(); - matcher.compute(left, right, disparity); + Mat other = new Mat(); + Imgproc.threshold(left, other, 150, 255, org.opencv.imgproc.Imgproc.THRESH_BINARY); + CustomTask.addTask(new DummyTask(other)); - CustomTask.addTask(new DummyTask(disparity)); }); utils.setInput(new MatTupleInput(Imgcodecs.imread("src/main/resources/left.png"), Imgcodecs.imread("src/main/resources/right.png"))); // utils.setInput(new MatInput(Imgcodecs.imread("src/main/resources/car.jpg"))); @@ -58,7 +54,6 @@ public class Main { @Override public CpuTask toCpuTask() { return () -> { -// this.mat.convertTo(this.mat, CvType.CV_8U, 0.25); // HighGui.imshow("AAAAA", this.mat); // HighGui.waitKey(); }; diff --git a/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/internal/tasks/imgproc/Threshold.java b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/internal/tasks/imgproc/Threshold.java new file mode 100644 index 0000000..ce76469 --- /dev/null +++ b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/internal/tasks/imgproc/Threshold.java @@ -0,0 +1,83 @@ +package de.unidue.nes.gpu.testframework.internal.tasks.imgproc; + +import org.bytedeco.opencv.global.opencv_cudaarithm; +import org.bytedeco.opencv.opencv_core.GpuMat; +import org.opencv.core.Mat; +import org.opencv.imgproc.Imgproc; + +import de.unidue.nes.gpu.testframework.internal.mathandling.MatPool; +import de.unidue.nes.gpu.testframework.tasks.CpuTask; +import de.unidue.nes.gpu.testframework.tasks.GpuTask; +import de.unidue.nes.gpu.testframework.tasks.Task; + +/** + * @author Roch P., Shahbaz Nejad B. + * + */ +public class Threshold implements Task { + + private final Mat src; + private final Mat dst; + private final double thresh; + private final double maxval; + private final int type; + + private final Mat originalSrc; + private final Mat originalDst; + + public Threshold(Mat src, Mat dst, double thresh, double maxval, int type) { + + this.src = src; + this.dst = dst; + this.thresh = thresh; + this.maxval = maxval; + this.type = type; + + this.originalSrc = new Mat(); + this.src.copyTo(this.originalSrc); + this.originalDst = new Mat(); + this.dst.copyTo(this.originalDst); + } + + @Override + public CpuTask toCpuTask() { + return () -> Imgproc.threshold(this.src, this.dst, this.thresh, this.maxval, this.type); + } + + @Override + public GpuTask toGpuTask() { + return new GpuTask() { + + private GpuMat gpuSrc; + private GpuMat gpuDst; + + @Override + public void run() { + opencv_cudaarithm.threshold(this.gpuSrc, this.gpuDst, Threshold.this.thresh, Threshold.this.maxval, Threshold.this.type); + } + + @Override + public void init() { + this.gpuSrc = MatPool.getUploadedGpuMat(Threshold.this.src, Threshold.this); + this.gpuDst = MatPool.getUploadedGpuMat(Threshold.this.dst, Threshold.this); + } + + @Override + public void cleanUp() { + + } + }; + } + + @Override + public String getDescription() { + return "Imgproc.threshold(" + this.src + ", " + this.dst + ", " + this.thresh + ", " + this.maxval + ", " + this.type + ")"; + } + + @Override + public void reset() { + this.originalSrc.copyTo(this.src); + this.originalDst.copyTo(this.dst); + } + +} diff --git a/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/opencv/Imgproc.java b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/opencv/Imgproc.java index 353dedb..7d80e2f 100644 --- a/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/opencv/Imgproc.java +++ b/gpu-app/src/main/java/de/unidue/nes/gpu/testframework/opencv/Imgproc.java @@ -8,6 +8,7 @@ import de.unidue.nes.gpu.testframework.internal.tasks.imgproc.Canny; import de.unidue.nes.gpu.testframework.internal.tasks.imgproc.CvtColor; import de.unidue.nes.gpu.testframework.internal.tasks.imgproc.GaussianBlur; import de.unidue.nes.gpu.testframework.internal.tasks.imgproc.MedianBlur; +import de.unidue.nes.gpu.testframework.internal.tasks.imgproc.Threshold; /** * A replacement for the real Imgproc @@ -47,4 +48,8 @@ public class Imgproc { public static void GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX, double sigmaY, int borderType) { TestPipeline.INSTANCE.addTask(new GaussianBlur(src, dst, ksize, sigmaX, sigmaY, borderType)); } + + public static void threshold(Mat src, Mat dst, double thresh, double maxval, int type) { + TestPipeline.INSTANCE.addTask(new Threshold(src, dst, thresh, maxval, type)); + } }