added copy and clone

This commit is contained in:
2020-05-07 16:05:04 +02:00
parent fbb5a28f23
commit b4464b3b76
4 changed files with 178 additions and 31 deletions
@@ -1,15 +1,10 @@
package de.unidue.nes.gpu.testframework;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.imgcodecs.Imgcodecs;
import de.unidue.nes.gpu.testframework.input.MatArrayInput;
import de.unidue.nes.gpu.testframework.opencv.DescriptorMatcher;
import de.unidue.nes.gpu.testframework.opencv.Features2d;
import de.unidue.nes.gpu.testframework.opencv.Imgproc;
import de.unidue.nes.gpu.testframework.opencv.ORB;
import de.unidue.nes.gpu.testframework.opencv.MatFunctions;
import de.unidue.nes.gpu.testframework.tasks.CustomTask;
import de.unidue.nes.gpu.testframework.tasks.DummyTask;
@@ -28,32 +23,12 @@ public class Main {
TestUtils<Mat[]> utils = new TestUtils<>();
utils.setCommandPipeline(arr -> {
Mat mat = arr.get()[0];
Mat other = arr.get()[1];
Mat other = MatFunctions.clone(mat);
// MatFunctions.copyTo(mat, other);
Imgproc.cvtColor(mat, mat, org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(other, other, org.opencv.imgproc.Imgproc.COLOR_BGR2GRAY);
ORB orb = ORB.create();
MatOfKeyPoint keypoints = new MatOfKeyPoint();
Mat descriptors = new Mat();
orb.detectAndCompute(mat, new Mat(), keypoints, descriptors);
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
Mat descriptors2 = new Mat();
orb.detectAndCompute(other, new Mat(), keypoints2, descriptors2);
DescriptorMatcher matcher = DescriptorMatcher.create(org.opencv.features2d.DescriptorMatcher.BRUTEFORCE_HAMMING);
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors2, descriptors, matches);
Mat out = new Mat();
Mat otherOut = new Mat();
Features2d.drawMatches(mat, keypoints, other, keypoints2, matches, out);
Features2d.drawKeypoints(mat, keypoints, otherOut);
CustomTask.addTask(new DummyTask(mat, out, otherOut));
CustomTask.addTask(new DummyTask(mat, other));
});
utils.setInput(new MatArrayInput(Imgcodecs.imread("src/main/resources/left_large.png"), Imgcodecs.imread("src/main/resources/right_large.png")));
utils.setInput(new MatArrayInput(Imgcodecs.imread("src/main/resources/left_small.png"), Imgcodecs.imread("src/main/resources/right_small.png")));
// utils.setInput(new MatInput(Imgcodecs.imread("src/main/resources/car.jpg")));
// utils.setInput(new MatInput(Imgcodecs.imread("src/main/resources/skyscraper_small.jpg")));
@@ -64,4 +39,4 @@ public class Main {
utils.runGPUTests(10);
utils.evaluate();
}
}
}
@@ -0,0 +1,69 @@
package de.unidue.nes.gpu.testframework.internal.tasks.mat;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
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 Clone implements Task {
private final Mat _this;
private final Mat clone;
public Clone(Mat _this) {
this._this = _this;
this.clone = _this.clone();
}
@Override
public CpuTask toCpuTask() {
this._this.copyTo(this.clone);
return () -> this._this.clone();
}
@Override
public GpuTask toGpuTask() {
this._this.copyTo(this.clone);
return new GpuTask() {
private GpuMat toClone;
@Override
public void run() {
this.toClone.clone();
}
@Override
public void init() {
this.toClone = MatPool.getUploadedGpuMat(Clone.this._this, Clone.this);
}
@Override
public void cleanUp() {
}
};
}
@Override
public String getDescription() {
return this._this + ".clone()";
}
@Override
public void reset() {
}
public Mat getClone() {
return this.clone;
}
}
@@ -0,0 +1,76 @@
package de.unidue.nes.gpu.testframework.internal.tasks.mat;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
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 CopyTo implements Task {
private final Mat _this;
private final Mat m;
private final Mat original_this;
private final Mat originalM;
public CopyTo(Mat _this, Mat m) {
this._this = _this;
this.m = m;
this.original_this = new Mat();
this._this.copyTo(this.original_this);
this.originalM = new Mat();
this.m.copyTo(this.originalM);
}
@Override
public CpuTask toCpuTask() {
return () -> {
this._this.copyTo(this.m);
};
}
@Override
public GpuTask toGpuTask() {
return new GpuTask() {
private GpuMat gpuThis;
private GpuMat gpuM;
@Override
public void run() {
this.gpuThis.copyTo(this.gpuM);
}
@Override
public void init() {
this.gpuThis = MatPool.getUploadedGpuMat(CopyTo.this._this, CopyTo.this);
this.gpuM = MatPool.getUploadedGpuMat(CopyTo.this.m, CopyTo.this);
}
@Override
public void cleanUp() {
// Nothing to clean up
}
};
}
@Override
public String getDescription() {
return this._this + ".copyTo(" + this.m + ")";
}
@Override
public void reset() {
this.original_this.copyTo(this._this);
this.originalM.copyTo(this.m);
}
}
@@ -0,0 +1,27 @@
package de.unidue.nes.gpu.testframework.opencv;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.testframework.internal.pipeline.TestPipeline;
import de.unidue.nes.gpu.testframework.internal.tasks.mat.Clone;
import de.unidue.nes.gpu.testframework.internal.tasks.mat.CopyTo;
/**
* @author Roch P., Shahbaz Nejad B.
*/
public class MatFunctions {
private MatFunctions() {
}
public static void copyTo(Mat _this, Mat m) {
TestPipeline.INSTANCE.addTask(new CopyTo(_this, m));
}
@Deprecated
public static Mat clone(Mat _this) {
Clone clone = new Clone(_this);
TestPipeline.INSTANCE.addTask(clone);
return clone.getClone();
}
}