added constant for test runs

This commit is contained in:
2020-03-04 13:26:17 +01:00
parent 9a504f5be4
commit 2241afe955
19 changed files with 50 additions and 21 deletions
@@ -13,6 +13,14 @@ import de.unidue.nes.gpu.events.ApplicationFinishedEvent;
import de.unidue.nes.gpu.events.GpuEventBus;
import de.unidue.nes.gpu.initialization.Initializer;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.tasks.taskdefinitions.ColoringTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.EdgeDetectionTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.FeatureMatchingTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.FilteringTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.HistogramTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.ResizingTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.StereoMatchingTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.ThresholdingTask;
/**
* Class containing the main method of this project.
@@ -23,6 +31,8 @@ public class GpuTestSystem {
private static final Logger LOG = LogManager.getLogger(GpuTestSystem.class);
public static final int TEST_RUNS = 100;
static {
Initializer.init();
}
@@ -74,7 +84,8 @@ public class GpuTestSystem {
private List<Task> getTasks() {
return Arrays.asList();
return Arrays.asList(new ThresholdingTask(), new FilteringTask(), new ResizingTask(), new ColoringTask(), new HistogramTask(), new EdgeDetectionTask(),
new FeatureMatchingTask(), new StereoMatchingTask());
}
}
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -18,7 +19,7 @@ public class CPUColoring {
LOG.debug(() -> "grayscaling an image of size " + image.size().toString());
Mat gray = new Mat();
long time = TimingService.measureTime(() -> Imgproc.cvtColor(image, gray, Imgproc.COLOR_BGR2GRAY), 1000);
long time = TimingService.measureTime(() -> Imgproc.cvtColor(image, gray, Imgproc.COLOR_BGR2GRAY), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "Grayscaling the image of size " + image.size() + " took " + time + "ms");
}
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -17,7 +18,7 @@ public class CPUEdgeDetection {
public void findEdges(Mat img) {
Mat edges = new Mat();
long time = TimingService.measureTime(() -> Imgproc.Canny(img, edges, 35, 100), 1000);
long time = TimingService.measureTime(() -> Imgproc.Canny(img, edges, 35, 100), GpuTestSystem.TEST_RUNS);
// HighGui.imshow("CPU edges", edges);
// HighGui.waitKey();
@@ -8,6 +8,7 @@ import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.DescriptorMatcher;
import org.opencv.features2d.ORB;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -37,7 +38,7 @@ public class CPUFeatureMatching {
orb.detectAndCompute(images[0], mask, imageKeypoints, imageDescriptors);
orb.detectAndCompute(images[1], mask, testKeyPoints, testDescriptors);
matcher.match(testDescriptors, imageDescriptors, matches);
}, 100);
}, GpuTestSystem.TEST_RUNS);
// Just for debugging
// List<DMatch> matchList = matches.toList();
// matchList = matchList.stream().sorted((match1, match2) -> Float.compare(match1.distance, match2.distance)).limit(25).collect(Collectors.toList());
@@ -6,6 +6,7 @@ import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -18,7 +19,7 @@ public class CPUFiltering {
public void runMedianFiltering(Mat img) {
Mat dst = new Mat();
long time = TimingService.measureTime(() -> Imgproc.medianBlur(img, dst, 15), 25);
long time = TimingService.measureTime(() -> Imgproc.medianBlur(img, dst, 15), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "median filter on size: " + img.size() + " took " + time + "ms");
}
@@ -27,7 +28,7 @@ public class CPUFiltering {
Mat dst = new Mat();
Size size = new Size(15, 15);
long time = TimingService.measureTime(() -> Imgproc.GaussianBlur(img, dst, size, 0, 0), 100);
long time = TimingService.measureTime(() -> Imgproc.GaussianBlur(img, dst, size, 0, 0), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "gaussian filter on size: " + img.size() + " took " + time + "ms");
}
@@ -10,6 +10,7 @@ import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -27,7 +28,7 @@ public class CPUHistogramming {
MatOfFloat ranges = new MatOfFloat(0, 256);
List<Mat> images = Collections.singletonList(img);
long time = TimingService.measureTime(() -> Imgproc.calcHist(images, channels, mask, hist, histSize, ranges), 100);
long time = TimingService.measureTime(() -> Imgproc.calcHist(images, channels, mask, hist, histSize, ranges), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "histogram for image of size " + img.size() + ": " + time + "ms");
}
@@ -6,6 +6,7 @@ import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -19,7 +20,7 @@ public class CPUResizing {
// LOG.debug(() -> "resizing image from size " + img.size() + " to size " + size);
Mat dst = new Mat();
long time = TimingService.measureTime(() -> Imgproc.resize(img, dst, size), 1000);
long time = TimingService.measureTime(() -> Imgproc.resize(img, dst, size), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "resizing image from size " + img.size() + " to size " + size + " took " + time + "ms.");
}
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import org.opencv.calib3d.StereoBM;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -18,7 +19,7 @@ public class CPUStereoMatching {
StereoBM matcher = StereoBM.create(256, 15);
Mat disparity = new Mat();
long time = TimingService.measureTime(() -> matcher.compute(leftImage, rightImage, disparity), 25);
long time = TimingService.measureTime(() -> matcher.compute(leftImage, rightImage, disparity), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "cpu stereo matching took of image size " + leftImage.size() + ": " + time + "ms");
// Just for debugging
@@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -17,7 +18,7 @@ public class CPUThresholding {
public void threshold(Mat mat) {
Mat res = new Mat();
long time = TimingService.measureTime(() -> Imgproc.threshold(mat, res, 128, 255, Imgproc.THRESH_BINARY), 1000);
long time = TimingService.measureTime(() -> Imgproc.threshold(mat, res, 128, 255, Imgproc.THRESH_BINARY), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "thresholding image from size " + mat.size() + " took " + time + "ms.");
// Mat show = new Mat();
@@ -7,6 +7,7 @@ import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -32,7 +33,7 @@ public class GPUColoring {
org.bytedeco.opencv.opencv_core.Mat javacvMat = new org.bytedeco.opencv.opencv_core.Mat()) {
this.converter.convert(image, javacvMat);
gpuImg.upload(javacvMat);
time = TimingService.measureTime(() -> opencv_cudaimgproc.cvtColor(gpuImg, grayImg, opencv_imgproc.COLOR_BGR2GRAY), 1000);
time = TimingService.measureTime(() -> opencv_cudaimgproc.cvtColor(gpuImg, grayImg, opencv_imgproc.COLOR_BGR2GRAY), GpuTestSystem.TEST_RUNS);
}
LOG.info(() -> "Grayscaling the image of size " + image.size() + " took " + time + "ms");
}
@@ -7,6 +7,7 @@ import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_cudaimgproc.CannyEdgeDetector;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -28,7 +29,7 @@ public class GPUEdgeDetection {
long time;
try (GpuMat gpuImg = new GpuMat(); GpuMat gpuEdges = new GpuMat(); CannyEdgeDetector detector = opencv_cudaimgproc.createCannyEdgeDetector(35, 100)) {
gpuImg.upload(javacvMat);
time = TimingService.measureTime(() -> detector.detect(gpuImg, gpuEdges), 1000);
time = TimingService.measureTime(() -> detector.detect(gpuImg, gpuEdges), GpuTestSystem.TEST_RUNS);
// gpuEdges.download(javacvMat);
// opencv_highgui.imshow("GPU edges", javacvMat);
@@ -11,6 +11,7 @@ import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_cudafeatures2d.DescriptorMatcher;
import org.bytedeco.opencv.opencv_cudafeatures2d.ORB;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -57,7 +58,7 @@ public class GPUFeatureMatching {
orb.detectAndCompute(gpuImg, mask, keypoints, imgDescriptors);
orb.detectAndCompute(gpuImg2, mask, testKeyPoints, testDescriptors);
matcher.match(testDescriptors, imgDescriptors, matches);
}, 100);
}, GpuTestSystem.TEST_RUNS);
// Just for debugging
@@ -9,6 +9,7 @@ import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_cudafilters.Filter;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -33,7 +34,7 @@ public class GPUFiltering {
gpuImg.upload(mat);
long time = TimingService.measureTime(() -> filter.apply(gpuImg, dst), 25);
long time = TimingService.measureTime(() -> filter.apply(gpuImg, dst), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "median filter on size: " + img.size() + " took " + time + "ms");
}
@@ -47,7 +48,7 @@ public class GPUFiltering {
gpuImg.upload(mat);
long time = TimingService.measureTime(() -> filter.apply(gpuImg, dst), 100);
long time = TimingService.measureTime(() -> filter.apply(gpuImg, dst), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "gaussian filter on size: " + img.size() + " took " + time + "ms");
}
@@ -6,6 +6,7 @@ import org.bytedeco.opencv.global.opencv_cudaimgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -28,7 +29,7 @@ public class GPUHistogramming {
this.converter.convert(img, m);
gpuMat.upload(m);
long time = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat, hist), 100);
long time = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat, hist), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "histogram for image of size " + img.size() + ": " + time + "ms");
}
}
@@ -7,6 +7,7 @@ import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -35,7 +36,7 @@ public class GPUResizing {
LOG.trace("uploading done");
LOG.trace("resizing now");
long time = TimingService.measureTime(() -> opencv_cudawarping.resize(gpuImg, dst, javacvSize), 1000);
long time = TimingService.measureTime(() -> opencv_cudawarping.resize(gpuImg, dst, javacvSize), GpuTestSystem.TEST_RUNS);
LOG.trace("resizing done");
// org.bytedeco.opencv.opencv_core.Mat res = new org.bytedeco.opencv.opencv_core.Mat();
@@ -7,6 +7,7 @@ import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_cudastereo.StereoBM;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -33,7 +34,7 @@ public class GPUStereoMatching {
right.upload(this.converter.convert2Javacv(rightImage));
long time = TimingService.measureTime(() -> matcher.compute(left, right, disparity), 25);
long time = TimingService.measureTime(() -> matcher.compute(left, right, disparity), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "gpu stereo matching took of image size " + leftImage.size() + ": " + time + "ms");
@@ -7,6 +7,7 @@ import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -29,7 +30,7 @@ public class GPUThresholding {
this.converter.convert(mat, javacvMat);
src.upload(javacvMat);
long time = TimingService.measureTime(() -> opencv_cudaarithm.threshold(src, dst, 128, 255, opencv_imgproc.THRESH_BINARY), 1000);
long time = TimingService.measureTime(() -> opencv_cudaarithm.threshold(src, dst, 128, 255, opencv_imgproc.THRESH_BINARY), GpuTestSystem.TEST_RUNS);
LOG.info(() -> "thresholding image from size " + mat.size() + " took " + time + "ms.");
@@ -8,6 +8,7 @@ import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
@@ -20,7 +21,7 @@ public class ConvertingTask implements Task {
private static final Logger LOG = LogManager.getLogger(ConvertingTask.class);
private static final int CONVERT_RUNS = 50;
private static final int CONVERT_RUNS = GpuTestSystem.TEST_RUNS;
@Override
public void runTask() {
@@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_core.Mat;
import de.unidue.nes.gpu.GpuTestSystem;
import de.unidue.nes.gpu.events.GpuEventBus;
import de.unidue.nes.gpu.events.TaskResultEvent;
import de.unidue.nes.gpu.tasks.Task;
@@ -29,7 +30,7 @@ public class UploadDownloadTask implements Task {
private static final Logger LOG = LogManager.getLogger(UploadDownloadTask.class);
private static final int ITERATIONS = 100;
private static final int ITERATIONS = GpuTestSystem.TEST_RUNS;
@Override
public void runTask() {