aded Canny measurement

This commit is contained in:
2020-03-16 13:20:51 +01:00
parent 056e4d8d94
commit ab7b6cdd1e
12 changed files with 103 additions and 84 deletions
@@ -13,7 +13,7 @@ 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.KernelTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
/**
* Class containing the main method of this project.
@@ -85,7 +85,9 @@ public class GpuTestSystem {
// new UploadDownloadTask(), //
// new PageLockedUploadDownloadTask(), //
// new PixelWiseTask(), //
new KernelTask());
// new KernelTask(), //
new ImgProcTask()//
);
}
}
@@ -1,13 +1,17 @@
package de.unidue.nes.gpu.events;
import static de.unidue.nes.gpu.events.TaskType.CPU_CANNY;
import static de.unidue.nes.gpu.events.TaskType.CPU_GAUSSIAN_BLUR;
import static de.unidue.nes.gpu.events.TaskType.CPU_GRAYSCALE;
import static de.unidue.nes.gpu.events.TaskType.CPU_HOUGH_CIRCLE;
import static de.unidue.nes.gpu.events.TaskType.CPU_MEDIAN_BLUR;
import static de.unidue.nes.gpu.events.TaskType.CPU_THRESHOLD;
import static de.unidue.nes.gpu.events.TaskType.GPU_CANNY;
import static de.unidue.nes.gpu.events.TaskType.GPU_COMBINED;
import static de.unidue.nes.gpu.events.TaskType.GPU_DOWNLOAD;
import static de.unidue.nes.gpu.events.TaskType.GPU_GAUSSIAN_BLUR;
import static de.unidue.nes.gpu.events.TaskType.GPU_GRAYSCALE;
import static de.unidue.nes.gpu.events.TaskType.GPU_HOUGH_CIRCLE;
import static de.unidue.nes.gpu.events.TaskType.GPU_MEDIAN_BLUR;
import static de.unidue.nes.gpu.events.TaskType.GPU_THRESHOLD;
import static de.unidue.nes.gpu.events.TaskType.GPU_UPLOAD;
@@ -19,8 +23,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
@@ -43,10 +49,13 @@ public class EventHandler {
private List<TaskResultEvent> events;
private Set<TaskType> testedTasks;
public EventHandler() {
GpuEventBus.INSTANCE.register(this);
this.events = new ArrayList<>();
this.testedTasks = new HashSet<>();
}
@Subscribe
@@ -61,6 +70,17 @@ public class EventHandler {
printUploadDownloadStuff();
printPixelwiseStuff();
printKernelTasks();
printImageProcTasks();
List<TaskResultEvent> notTested = this.events.stream().filter(evt -> !this.testedTasks.contains(evt.getType())).collect(Collectors.toList());
if (!notTested.isEmpty()) {
LOG.warn("Following were not tested:");
notTested.stream().map(TaskResultEvent::getType).distinct().forEach(t -> LOG.warn(t::toString));
}
}
private void printImageProcTasks() {
printTable("imgproc table", new TaskType[] { CPU_CANNY, GPU_CANNY, CPU_HOUGH_CIRCLE, GPU_HOUGH_CIRCLE });
}
private void printKernelTasks() {
@@ -78,6 +98,7 @@ public class EventHandler {
private void printTable(String tablename, TaskType[] types) {
final boolean addHorizontalLines = true;
this.testedTasks.addAll(Arrays.asList(types));
List<TaskResultEvent> eventList = this.events.stream().filter(ev -> Arrays.asList(types).contains(ev.getType())).collect(Collectors.toList());
if (eventList.isEmpty()) {
return;
@@ -7,8 +7,9 @@ public enum TaskType {
GPU_UPLOAD("uploading"), GPU_DOWNLOAD("downloading"), GPU_COMBINED("combined"), //
PAGE_LOCKED_GPU_UPLOAD("page-locked uploading"), PAGE_LOCKED_GPU_DOWNLOAD("page-locked downloading"), PAGE_LOCKED_GPU_COMBINED("page-locked combined"),
CPU_THRESHOLD("CPU threshold"), GPU_THRESHOLD("GPU threshold"), CPU_GRAYSCALE("CPU grayscale"), GPU_GRAYSCALE("GPU grayscale"), //
CPU_MEDIAN_BLUR("CPU median filter"), GPU_MEDIAN_BLUR("GPU median filter"), CPU_GAUSSIAN_BLUR("CPU gaussian filter"),
GPU_GAUSSIAN_BLUR("GPU gaussian filter");
CPU_MEDIAN_BLUR("CPU median filter"), GPU_MEDIAN_BLUR("GPU median filter"), //
CPU_GAUSSIAN_BLUR("CPU gaussian filter"), GPU_GAUSSIAN_BLUR("GPU gaussian filter"), //
CPU_CANNY("CPU edge detection"), GPU_CANNY("GPU edge detection"), CPU_HOUGH_CIRCLE("CPU circle detection"), GPU_HOUGH_CIRCLE("GPU circle detection");
private String title;
@@ -5,7 +5,11 @@ 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.events.GpuEventBus;
import de.unidue.nes.gpu.events.TaskResultEvent;
import de.unidue.nes.gpu.events.TaskType;
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
import de.unidue.nes.gpu.utils.TimeDto;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -18,11 +22,12 @@ public class CPUEdgeDetection {
public void findEdges(Mat img) {
Mat edges = new Mat();
long time = TimingService.measureTime(() -> Imgproc.Canny(img, edges, 35, 100), GpuTestSystem.TEST_RUNS);
TimeDto time = TimingService.testPerformance(() -> Imgproc.Canny(img, edges, 35, 100), ImgProcTask.TEST_RUNS);
// HighGui.imshow("CPU edges", edges);
// HighGui.waitKey();
LOG.info(() -> "cpu execution time for image of size " + img.size() + ": " + time + "ms");
GpuEventBus.INSTANCE.post(new TaskResultEvent("", ImgProcTask.TEST_RUNS, img.size(), TaskType.CPU_CANNY, time));
}
}
@@ -3,10 +3,13 @@ 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.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.events.GpuEventBus;
import de.unidue.nes.gpu.events.TaskResultEvent;
import de.unidue.nes.gpu.events.TaskType;
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
import de.unidue.nes.gpu.utils.TimeDto;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -16,41 +19,15 @@ public class CPUHoughCircles {
private static final Logger LOG = LogManager.getLogger(CPUHoughCircles.class);
private static final String IMG_PATH = "src/main/resources/circlesImage.png";
private Mat[] testImages;
public CPUHoughCircles() {
this.testImages = new Mat[] { Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH) };
Imgproc.resize(this.testImages[1], this.testImages[1], new Size(), 2.5, 2.5);
Imgproc.resize(this.testImages[2], this.testImages[2], new Size(), 5, 5);
Imgproc.resize(this.testImages[3], this.testImages[3], new Size(), 10, 10);
Imgproc.cvtColor(this.testImages[0], this.testImages[0], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[1], this.testImages[1], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[2], this.testImages[2], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[3], this.testImages[3], Imgproc.COLOR_BGR2GRAY);
}
public void detectCircles() {
public void detectCircles(Mat img) {
Mat circles = new Mat();
long time1 = TimingService.measureTime(
() -> Imgproc.HoughCircles(this.testImages[0], circles, Imgproc.HOUGH_GRADIENT, 1, (double) this.testImages[0].rows() / 10, 64, 40), 50);
TimeDto time = TimingService.testPerformance(() -> Imgproc.HoughCircles(img, circles, Imgproc.HOUGH_GRADIENT, 2.5, (double) img.rows() / 5, 64, 50),
ImgProcTask.TEST_RUNS);
long time2 = TimingService.measureTime(
() -> Imgproc.HoughCircles(this.testImages[1], circles, Imgproc.HOUGH_GRADIENT, 1, (double) this.testImages[1].rows() / 10, 64, 50), 25);
LOG.info(() -> "image size: " + img.size() + ": " + time + "ms");
GpuEventBus.INSTANCE.post(new TaskResultEvent("", ImgProcTask.TEST_RUNS, img.size(), TaskType.CPU_HOUGH_CIRCLE, time));
long time3 = TimingService.measureTime(
() -> Imgproc.HoughCircles(this.testImages[2], circles, Imgproc.HOUGH_GRADIENT, 1, (double) this.testImages[2].rows() / 10, 64, 45), 10);
// not comparable to gpu
// long time4 = TimingService.measureTime(
// () -> Imgproc.HoughCircles(this.testImages[3], circles, Imgproc.HOUGH_GRADIENT, 1, (double) this.testImages[3].rows() / 10, 64, 50), 1);
LOG.info(() -> "original image: " + time1 + "ms");
LOG.info(() -> "2.5x original image: " + time2 + "ms");
LOG.info(() -> "5x original image: " + time3 + "ms");
// LOG.info(() -> "10x original image: " + time4 + "ms");
}
}
@@ -7,8 +7,12 @@ 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.events.GpuEventBus;
import de.unidue.nes.gpu.events.TaskResultEvent;
import de.unidue.nes.gpu.events.TaskType;
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimeDto;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -26,17 +30,19 @@ public class GPUEdgeDetection {
public void findEdges(Mat img) {
org.bytedeco.opencv.opencv_core.Mat javacvMat = new org.bytedeco.opencv.opencv_core.Mat();
this.converter.convert(img, javacvMat);
long time;
TimeDto 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), GpuTestSystem.TEST_RUNS);
time = TimingService.testPerformance(() -> detector.detect(gpuImg, gpuEdges), ImgProcTask.TEST_RUNS);
// gpuEdges.download(javacvMat);
// opencv_highgui.imshow("GPU edges", javacvMat);
// opencv_highgui.waitKey();
}
LOG.info(() -> "gpu execution timefor image of size " + img.size() + ": " + time + "ms");
LOG.info(() -> "gpu execution time for image of size " + img.size() + ": " + time + "ms");
GpuEventBus.INSTANCE.post(new TaskResultEvent("", ImgProcTask.TEST_RUNS, img.size(), TaskType.GPU_CANNY, time));
}
}
@@ -6,11 +6,13 @@ import org.bytedeco.opencv.global.opencv_cudaimgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_cudaimgproc.HoughCirclesDetector;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.events.GpuEventBus;
import de.unidue.nes.gpu.events.TaskResultEvent;
import de.unidue.nes.gpu.events.TaskType;
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimeDto;
import de.unidue.nes.gpu.utils.TimingService;
/**
@@ -20,53 +22,24 @@ public class GPUHoughCircles {
private static final Logger LOG = LogManager.getLogger(GPUHoughCircles.class);
private static final String IMG_PATH = "src/main/resources/circlesImage.png";
private Mat[] testImages;
private MatConverter converter;
public GPUHoughCircles() {
this.testImages = new Mat[] { Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH), Imgcodecs.imread(IMG_PATH) };
Imgproc.resize(this.testImages[1], this.testImages[1], new Size(), 2.5, 2.5);
Imgproc.resize(this.testImages[2], this.testImages[2], new Size(), 5, 5);
Imgproc.resize(this.testImages[3], this.testImages[3], new Size(), 10, 10);
Imgproc.cvtColor(this.testImages[0], this.testImages[0], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[1], this.testImages[1], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[2], this.testImages[2], Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(this.testImages[3], this.testImages[3], Imgproc.COLOR_BGR2GRAY);
this.converter = new MatConverter();
}
public void detectCircles() {
public void detectCircles(Mat img) {
GpuMat circles = new GpuMat();
GpuMat gpuImg = new GpuMat();
HoughCirclesDetector detector1 = opencv_cudaimgproc.createHoughCirclesDetector(1, this.testImages[0].rows() / 10, 64, 40, 32, 256);
org.bytedeco.opencv.opencv_core.Mat tmp = this.converter.convert2Javacv(this.testImages[0]);
HoughCirclesDetector detector = opencv_cudaimgproc.createHoughCirclesDetector(1, img.rows() / 10, 64, 40, 32, 256);
org.bytedeco.opencv.opencv_core.Mat tmp = this.converter.convert2Javacv(img);
gpuImg.upload(tmp);
long time1 = TimingService.measureTime(() -> detector1.detect(gpuImg, circles), 50);
TimeDto time = TimingService.testPerformance(() -> detector.detect(gpuImg, circles), ImgProcTask.TEST_RUNS);
HoughCirclesDetector detector2 = opencv_cudaimgproc.createHoughCirclesDetector(1, this.testImages[1].rows() / 10, 64, 40, 32, 256);
tmp = this.converter.convert2Javacv(this.testImages[1]);
gpuImg.upload(tmp);
long time2 = TimingService.measureTime(() -> detector2.detect(gpuImg, circles), 25);
LOG.info(() -> "image of size " + img.size() + ": " + time + "ms");
GpuEventBus.INSTANCE.post(new TaskResultEvent("", ImgProcTask.TEST_RUNS, img.size(), TaskType.GPU_HOUGH_CIRCLE, time));
HoughCirclesDetector detector3 = opencv_cudaimgproc.createHoughCirclesDetector(1, this.testImages[2].rows() / 10, 64, 40, 32, 256);
tmp = this.converter.convert2Javacv(this.testImages[2]);
gpuImg.upload(tmp);
long time3 = TimingService.measureTime(() -> detector3.detect(gpuImg, circles), 10);
// throws out of memory error :(
// HoughCirclesDetector detector4 = opencv_cudaimgproc.createHoughCirclesDetector(1, this.testImages[3].rows() / 10, 64, 40, 32, 256);
// org.bytedeco.opencv.opencv_core.Mat tmp = this.converter.convert2Javacv(this.testImages[3]);
// gpuImg.upload(tmp);
// long time4 = TimingService.measureTime(() -> detector4.detect(gpuImg, circles), 1);
LOG.info(() -> "original image: " + time1 + "ms");
LOG.info(() -> "2.5x original image: " + time2 + "ms");
LOG.info(() -> "5x original image: " + time3 + "ms");
// LOG.info(() -> "10x original image: " + time4 + "ms");
}
}
@@ -26,7 +26,7 @@ public class EdgeDetectionTask implements Task {
@Override
public void runTask() {
Mat[] images = ImageLoader.getTestImages();
Mat[] images = ImageLoader.getImgprocImages();
Arrays.stream(images).forEach(img -> Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY));
Arrays.stream(images).forEach(this.cpuTask::findEdges);
@@ -17,5 +17,6 @@ public class HomographyTask {
// no gpu implementation for findHomography
this.gpuTask = new GPUHomography();
}
}
@@ -1,8 +1,14 @@
package de.unidue.nes.gpu.tasks.taskdefinitions;
import java.util.Arrays;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.tasks.cputasks.CPUHoughCircles;
import de.unidue.nes.gpu.tasks.gputasks.GPUHoughCircles;
import de.unidue.nes.gpu.utils.ImageLoader;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -20,8 +26,11 @@ public class HoughCircleTask implements Task {
@Override
public void runTask() {
this.cpuTask.detectCircles();
this.gpuTask.detectCircles();
Mat[] images = ImageLoader.getImgprocImages();
Arrays.stream(images).forEach(img -> Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY));
Arrays.stream(images).forEach(this.cpuTask::detectCircles);
Arrays.stream(images).forEach(this.gpuTask::detectCircles);
}
}
@@ -0,0 +1,20 @@
package de.unidue.nes.gpu.tasks.taskdefinitions;
import de.unidue.nes.gpu.tasks.Task;
/**
* @author Roch P., Shahbaz Nejad B.
*/
public class ImgProcTask implements Task {
public static final int TEST_RUNS = 2;
@Override
public void runTask() {
EdgeDetectionTask edgeTask = new EdgeDetectionTask();
HoughCircleTask circleTask = new HoughCircleTask();
edgeTask.runTask();
// circleTask.runTask();//TODO: takes forever to test :(
}
}
@@ -51,4 +51,8 @@ public class ImageLoader {
public static Mat[] getTestImagesForKernelOperations() {
return getLargeImageDataset();
}
public static Mat[] getImgprocImages() {
return getLargeImageDataset();
}
}