added customizable input
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package de.unidue.nes.gpu.testframework;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public interface Input<T> {
|
||||
|
||||
void copyTo(Input<T> other);
|
||||
|
||||
Input<T> createCopy();
|
||||
|
||||
T get();
|
||||
|
||||
Mat toMat();
|
||||
}
|
||||
@@ -17,15 +17,18 @@ public class Main {
|
||||
// main method only used to test
|
||||
public static void main(String[] args) {
|
||||
|
||||
TestUtils utils = new TestUtils();
|
||||
utils.setCommandPipeline(mat -> {
|
||||
TestUtils<Mat> utils = new TestUtils<>();
|
||||
utils.setCommandPipeline(matInput -> {
|
||||
Mat mat = matInput.get();
|
||||
Mat edges = new Mat();
|
||||
Imgproc.cvtColor(mat, mat, org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY);
|
||||
Imgproc.Canny(mat, edges, 15, 45);
|
||||
});
|
||||
utils.setInputImage(Imgcodecs.imread("src/main/resources/car.jpg"));
|
||||
utils.setInput(new MatInput(Imgcodecs.imread("src/main/resources/car.jpg")));
|
||||
utils.initializeCommands();
|
||||
utils.warmupGPUTests(5);
|
||||
utils.warmupCPUTests(5);
|
||||
utils.runCPUTests(10);
|
||||
utils.runGPUTests(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package de.unidue.nes.gpu.testframework;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class MatInput implements Input<Mat> {
|
||||
|
||||
private final Mat mat;
|
||||
|
||||
public MatInput(Mat mat) {
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(Input<Mat> other) {
|
||||
this.mat.copyTo(other.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Input<Mat> createCopy() {
|
||||
Mat newMat = new Mat();
|
||||
this.mat.copyTo(newMat);
|
||||
return new MatInput(newMat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat get() {
|
||||
return this.mat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mat toMat() {
|
||||
return get();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bytedeco.opencv.opencv_core.GpuMat;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import de.unidue.nes.gpu.testframework.exception.AlreadyInitializedException;
|
||||
import de.unidue.nes.gpu.testframework.exception.NotInitializedException;
|
||||
@@ -21,16 +20,16 @@ import de.unidue.nes.gpu.testframework.tasks.Task;
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*
|
||||
*/
|
||||
public class TestUtils {
|
||||
public class TestUtils<T> {
|
||||
|
||||
private static final Runnable NOOP = () -> {
|
||||
};
|
||||
|
||||
private Consumer<Mat> commands;
|
||||
private Consumer<Input<T>> commands;
|
||||
|
||||
private Mat originalInput;
|
||||
private Input<T> originalInput;
|
||||
|
||||
private Mat input;
|
||||
private Input<T> input;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
@@ -41,16 +40,15 @@ public class TestUtils {
|
||||
/**
|
||||
* @param commands
|
||||
*/
|
||||
public void setCommandPipeline(Consumer<Mat> commands) {
|
||||
public void setCommandPipeline(Consumer<Input<T>> commands) {
|
||||
checkNotInitialized();
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void setInputImage(Mat input) {
|
||||
public void setInput(Input<T> input) {
|
||||
checkNotInitialized();
|
||||
this.originalInput = input;
|
||||
this.input = new Mat();
|
||||
this.originalInput.copyTo(this.input);
|
||||
this.input = input.createCopy();
|
||||
}
|
||||
|
||||
public void initializeCommands() {
|
||||
@@ -97,7 +95,7 @@ public class TestUtils {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
this.originalInput.copyTo(this.input);
|
||||
try (org.bytedeco.opencv.opencv_core.Mat jcvMat = new org.bytedeco.opencv.opencv_core.Mat(); GpuMat gpuMat = new GpuMat()) {
|
||||
MatConverter.copyMat(this.input, jcvMat);
|
||||
MatConverter.copyMat(this.input.toMat(), jcvMat);
|
||||
gpuMat.upload(jcvMat);
|
||||
gpuMat.download(jcvMat);
|
||||
}
|
||||
@@ -139,7 +137,6 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
private void testUploadAndDownload(int iterations) {
|
||||
|
||||
testUpload(iterations);
|
||||
testDownload(iterations);
|
||||
}
|
||||
@@ -152,7 +149,7 @@ public class TestUtils {
|
||||
jcvMat[0] = new org.bytedeco.opencv.opencv_core.Mat();
|
||||
gpuMat[0] = new GpuMat();
|
||||
this.originalInput.copyTo(this.input);
|
||||
MatConverter.copyMat(this.input, jcvMat[0]);
|
||||
MatConverter.copyMat(this.input.toMat(), jcvMat[0]);
|
||||
gpuMat[0].upload(jcvMat[0]);
|
||||
};
|
||||
Runnable test = () -> gpuMat[0].download(jcvMat[0]);
|
||||
@@ -172,7 +169,7 @@ public class TestUtils {
|
||||
jcvMat[0] = new org.bytedeco.opencv.opencv_core.Mat();
|
||||
gpuMat[0] = new GpuMat();
|
||||
this.originalInput.copyTo(this.input);
|
||||
MatConverter.copyMat(this.input, jcvMat[0]);
|
||||
MatConverter.copyMat(this.input.toMat(), jcvMat[0]);
|
||||
};
|
||||
Runnable test = () -> gpuMat[0].upload(jcvMat[0]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user