added thresholding
This commit is contained in:
@@ -11,7 +11,7 @@ import org.apache.logging.log4j.core.config.Configuration;
|
||||
|
||||
import de.unidue.nes.gpu.initialization.Initializer;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.StereoMatchingTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.ThresholdingTask;
|
||||
|
||||
/**
|
||||
* Class containing the main method of this project.
|
||||
@@ -42,6 +42,10 @@ public class GpuTestSystem {
|
||||
|
||||
// run tasks for the first time if some dlls are loaded lazily
|
||||
tasks.forEach(Task::runTask);
|
||||
|
||||
// run again to be sure that nothing is loaded anymore
|
||||
tasks.forEach(Task::runTask);// I'm not sure if this is necessary
|
||||
|
||||
config.getRootLogger().setLevel(originalLevel);
|
||||
ctx.updateLoggers();
|
||||
LOG.info("Now starting tasks to measure performance");
|
||||
@@ -51,7 +55,7 @@ public class GpuTestSystem {
|
||||
|
||||
private List<Task> getTasks() {
|
||||
|
||||
return Arrays.asList(new StereoMatchingTask());
|
||||
return Arrays.asList(new ThresholdingTask());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.unidue.nes.gpu.tasks.cputasks;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import de.unidue.nes.gpu.utils.TimingService;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class CPUThresholding {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(CPUThresholding.class);
|
||||
|
||||
public void threshold(Mat mat) {
|
||||
Mat res = new Mat();
|
||||
|
||||
long time = TimingService.measureTime(() -> Imgproc.threshold(mat, res, 128, 255, Imgproc.THRESH_BINARY), 1000);
|
||||
|
||||
LOG.info(() -> "thresholding image from size " + mat.size() + " took " + time + "ms.");
|
||||
// Mat show = new Mat();
|
||||
// Imgproc.resize(mat, show, new Size(1000, 662));
|
||||
// Imgproc.resize(res, res, new Size(1000, 662));
|
||||
//
|
||||
// HighGui.imshow("image", show);
|
||||
// HighGui.imshow("thresholded image", res);
|
||||
// HighGui.waitKey();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package de.unidue.nes.gpu.tasks.gputasks;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bytedeco.opencv.global.opencv_cudaarithm;
|
||||
import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
import org.bytedeco.opencv.opencv_core.GpuMat;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import de.unidue.nes.gpu.utils.MatConverter;
|
||||
import de.unidue.nes.gpu.utils.TimingService;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class GPUThresholding {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(GPUThresholding.class);
|
||||
|
||||
private MatConverter converter;
|
||||
|
||||
public GPUThresholding() {
|
||||
this.converter = new MatConverter();
|
||||
}
|
||||
|
||||
public void threshold(Mat mat) {
|
||||
GpuMat src = new GpuMat();
|
||||
org.bytedeco.opencv.opencv_core.Mat javacvMat = new org.bytedeco.opencv.opencv_core.Mat();
|
||||
this.converter.convert(mat, javacvMat);
|
||||
src.upload(javacvMat);
|
||||
GpuMat dst = new GpuMat();
|
||||
|
||||
long time = TimingService.measureTime(() -> opencv_cudaarithm.threshold(src, dst, 128, 255, opencv_imgproc.THRESH_BINARY), 1000);
|
||||
|
||||
LOG.info(() -> "thresholding image from size " + mat.size() + " took " + time + "ms.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,44 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.cputasks.CPUThresholding;
|
||||
import de.unidue.nes.gpu.tasks.gputasks.GPUThresholding;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class ThresholdingTask implements Task {
|
||||
|
||||
private CPUThresholding cpuTask;
|
||||
|
||||
private GPUThresholding gpuTask;
|
||||
|
||||
public ThresholdingTask() {
|
||||
this.cpuTask = new CPUThresholding();
|
||||
this.gpuTask = new GPUThresholding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
// load images to threshold
|
||||
Mat[] images = new Mat[] { Imgcodecs.imread("src/main/resources/skyscraper_small.jpg"), Imgcodecs.imread("src/main/resources/skyscraper_medium.jpg"),
|
||||
Imgcodecs.imread("src/main/resources/skyscraper_large.jpg") };
|
||||
// convert to grayscale
|
||||
for (Mat img : images) {
|
||||
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
|
||||
}
|
||||
|
||||
this.cpuTask.threshold(images[0]);
|
||||
this.cpuTask.threshold(images[1]);
|
||||
this.cpuTask.threshold(images[2]);
|
||||
|
||||
this.gpuTask.threshold(images[0]);
|
||||
this.gpuTask.threshold(images[1]);
|
||||
this.gpuTask.threshold(images[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user