added better description generation

This commit is contained in:
2020-05-08 11:19:16 +02:00
parent e0afea734b
commit f717d655c6
27 changed files with 268 additions and 81 deletions
@@ -24,18 +24,15 @@ public class Main {
TestUtils<Mat[]> utils = new TestUtils<>();
utils.setCommandPipeline(arr -> {
Mat first = arr.get()[0];
Mat second = arr.get()[1];
Mat third = arr.get()[2];
Mat dst1 = new Mat();
Mat dst2 = new Mat();
Mat dst3 = new Mat();
Imgproc.resize(first, dst1, new Size(200, 200));
Imgproc.resize(second, dst2, new Size(0, 0), 1.5, 1.5);
Imgproc.resize(third, third, new Size(0, 0), 0.75, 0.5);
Imgproc.resize(third, dst3, new Size(), 3, 3, org.opencv.imgproc.Imgproc.INTER_CUBIC);
Imgproc.resize(first, dst1, new Size(0, 0), 2, 2);
Imgproc.resize(dst1, dst2, new Size(), 2, 2);
Imgproc.resize(dst2, dst3, first.size());
CustomTask.addTask(new DummyTask(dst1, dst2, dst3));
CustomTask.addTask(new DummyTask(dst3));
});
utils.setInput(new MatArrayInput(Imgcodecs.imread("src/main/resources/left_small.png"), Imgcodecs.imread("src/main/resources/skyscraper_small.jpg"),
Imgcodecs.imread("src/main/resources/car.jpg")));
@@ -44,10 +41,10 @@ public class Main {
// utils.setInput(new MatInput(Imgcodecs.imread("src/main/resources/skyscraper_small.jpg")));
utils.initializeCommands();
utils.warmupCPUTests(5);
utils.runCPUTests(10);
utils.warmupGPUTests(5);
utils.runGPUTests(10);
utils.warmupCPUTests(1);
utils.runCPUTests(5);
utils.warmupGPUTests(1);
utils.runGPUTests(5);
utils.evaluate();
}
}
@@ -77,9 +77,20 @@ public class TestUtils<T> {
checkNotInitialized();
checkFieldsAreSet();
this.commands.accept(this.input);
initDescriptions();
this.initialized = true;
}
private void initDescriptions() {
List<Task> tasks = TestPipeline.INSTANCE.getPipeline();
this.originalInput.copyTo(this.input);
for (Task t : tasks) {
t.initDescription();
t.toCpuTask().run();
}
resetTasks();
}
private void checkFieldsAreSet() {
Objects.requireNonNull(this.commands);
Objects.requireNonNull(this.originalInput);
@@ -186,6 +186,12 @@ public class ResultHandler {
return null;
}
/**
* this task is used as first and last node of the resulting graph. It is never
* run.
*
* @author Roch P., Shahbaz Nejad B.
*/
private static final class DummyTask implements Task {
@Override
@@ -208,5 +214,10 @@ public class ResultHandler {
}
@Override
public void initDescription() {
}
}
}
@@ -15,7 +15,10 @@ public class DescriptorMatcher_create implements Task {
private final int cudaNormType;
private String descr;
public DescriptorMatcher_create(int id, int matcherType) {
this.descr = "";
this.matcherType = matcherType;
this.cudaNormType = getNormType(matcherType);
DescriptorMatchers.addMatcher(org.opencv.features2d.DescriptorMatcher.create(matcherType), id);
@@ -65,12 +68,17 @@ public class DescriptorMatcher_create implements Task {
@Override
public String getDescription() {
return "DescriptorMatcher.create(" + this.matcherType + ")";
return this.descr;
}
@Override
public void reset() {
// Nothing to reset
}
@Override
public void initDescription() {
this.descr = "DescriptorMatcher.create(" + this.matcherType + ")";
}
}
@@ -28,7 +28,11 @@ public class DescriptorMatcher_match implements Task {
private final Mat originalTrainDescriptors;
private final MatOfDMatch originalMatches;
private String descr;
public DescriptorMatcher_match(int id, Mat queryDescriptors, Mat trainDescriptors, MatOfDMatch matches) {
this.descr = "";
this.id = id;
this.theMatcher = DescriptorMatchers.getById(this.id);
@@ -107,7 +111,7 @@ public class DescriptorMatcher_match implements Task {
@Override
public String getDescription() {
return "DescriptorMatcher.match(" + this.queryDescriptors + ", " + this.trainDescriptors + ", " + this.matches + ")";
return this.descr;
}
@Override
@@ -117,4 +121,9 @@ public class DescriptorMatcher_match implements Task {
this.originalMatches.copyTo(this.matches);
}
@Override
public void initDescription() {
this.descr = "DescriptorMatcher.match(" + this.queryDescriptors + ", " + this.trainDescriptors + ", " + this.matches + ")";
}
}
@@ -21,6 +21,8 @@ public class DrawKeypoints implements Task {
private final MatOfKeyPoint originalKeypoints;
private final Mat originalOutImage;
private String descr = "";
public DrawKeypoints(Mat image, MatOfKeyPoint keypoints, Mat outImage) {
this.image = image;
this.keypoints = keypoints;
@@ -46,7 +48,7 @@ public class DrawKeypoints implements Task {
@Override
public String getDescription() {
return "Features2d.drawKeypoints(" + this.image + ", " + this.keypoints + ", " + this.outImage + ")";
return this.descr;
}
@Override
@@ -56,4 +58,9 @@ public class DrawKeypoints implements Task {
this.originalOutImage.copyTo(this.outImage);
}
@Override
public void initDescription() {
this.descr = "Features2d.drawKeypoints(" + this.image + ", " + this.keypoints + ", " + this.outImage + ")";
}
}
@@ -28,6 +28,8 @@ public class DrawMatches implements Task {
private final MatOfDMatch originalMatches1to2;
private final Mat originalOutImg;
private String descr = "";
public DrawMatches(Mat img1, MatOfKeyPoint keypoints1, Mat img2, MatOfKeyPoint keypoints2, MatOfDMatch matches1to2, Mat outImg) {
this.img1 = img1;
this.keypoints1 = keypoints1;
@@ -64,8 +66,7 @@ public class DrawMatches implements Task {
@Override
public String getDescription() {
return "Features2d.drawMatches(" + this.img1 + ", " + this.keypoints1 + ", " + this.img2 + ", " + this.keypoints2 + ", " + this.matches1to2 + ", "
+ this.outImg + ")";
return this.descr;
}
@Override
@@ -78,4 +79,10 @@ public class DrawMatches implements Task {
this.originalOutImg.copyTo(this.outImg);
}
@Override
public void initDescription() {
this.descr = "Features2d.drawMatches(" + this.img1 + ", " + this.keypoints1 + ", " + this.img2 + ", " + this.keypoints2 + ", " + this.matches1to2 + ", "
+ this.outImg + ")";
}
}
@@ -80,4 +80,9 @@ public class DownloadTask implements Task {
return "Download of " + this.mat;
}
@Override
public void initDescription() {
}
}
@@ -86,4 +86,9 @@ public class PagelockedUploadTask implements Task {
return "Page-locked upload of " + this.mat;
}
@Override
public void initDescription() {
}
}
@@ -53,8 +53,12 @@ public class PipelineTask implements Task {
@Override
public void reset() {
// TODO Auto-generated method stub
// Nothing to reset
}
@Override
public void initDescription() {
// no description for complete pipeline
}
}
@@ -79,4 +79,9 @@ public class UploadTask implements Task {
return "Upload of " + this.mat;
}
@Override
public void initDescription() {
}
}
@@ -28,6 +28,8 @@ public class Canny implements Task {
private final Mat originalImage;
private final Mat originalEdges;
private String descr = "";
public Canny(Mat image, Mat edges, double threshold1, double threshold2) {
this.image = image;
this.edges = edges;
@@ -75,7 +77,7 @@ public class Canny implements Task {
@Override
public String getDescription() {
return "Imgproc.Canny(" + Objects.toString(this.image) + ", " + Objects.toString(this.edges) + ", " + this.threshold1 + ", " + this.threshold2 + ")";
return this.descr;
}
@Override
@@ -84,4 +86,10 @@ public class Canny implements Task {
this.originalEdges.copyTo(this.edges);
}
@Override
public void initDescription() {
this.descr = "Imgproc.Canny(" + Objects.toString(this.image) + ", " + Objects.toString(this.edges) + ", " + this.threshold1 + ", " + this.threshold2
+ ")";
}
}
@@ -33,6 +33,8 @@ public class CvtColor implements Task {
private final Mat originalDst;
private String descr = "";
public CvtColor(Mat src, Mat dst, int code) {
this.src = src;
this.dst = dst;
@@ -64,6 +66,8 @@ public class CvtColor implements Task {
Imgproc.cvtColor(CvtColor.this.src, CvtColor.this.dst, CvtColor.this.code);
} else if (CvtColor.this.numParams == 4) {
Imgproc.cvtColor(CvtColor.this.src, CvtColor.this.dst, CvtColor.this.code, CvtColor.this.dstCn);
} else {
throw new RuntimeException();
}
};
}
@@ -82,6 +86,8 @@ public class CvtColor implements Task {
opencv_cudaimgproc.cvtColor(this.gpuSrc, this.gpuDst, CvtColor.this.code);
} else if (CvtColor.this.numParams == 4) {
opencv_cudaimgproc.cvtColor(this.gpuSrc, this.gpuDst, CvtColor.this.code, CvtColor.this.dstCn, null);
} else {
throw new RuntimeException();
}
}
@@ -100,12 +106,7 @@ public class CvtColor implements Task {
@Override
public String getDescription() {
if (this.numParams == 3) {
return "Imgproc.cvtColor(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.code + ")";
} else if (this.numParams == 4) {
return "Imgproc.cvtColor(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.code + ", " + this.dstCn + ")";
}
return "";
return this.descr;
}
@Override
@@ -114,4 +115,14 @@ public class CvtColor implements Task {
this.originalDst.copyTo(this.dst);
}
@Override
public void initDescription() {
if (this.numParams == 3) {
this.descr = "Imgproc.cvtColor(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.code + ")";
} else if (this.numParams == 4) {
this.descr = "Imgproc.cvtColor(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.code + ", " + this.dstCn + ")";
}
throw new RuntimeException();
}
}
@@ -34,6 +34,8 @@ public class GaussianBlur implements Task {
private final Mat originalSrc;
private final Mat originalDst;
private String descr = "";
public GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX) {
this.borderType = 0;
this.sigmaY = 0;
@@ -153,19 +155,7 @@ public class GaussianBlur implements Task {
@Override
public String getDescription() {
switch (this.numParams) {
case 4:
return "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + ")";
case 5:
return "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + +this.sigmaY + ")";
case 6:
return "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + +this.sigmaY + this.borderType + ")";
default:
return "";
}
return this.descr;
}
@Override
@@ -174,4 +164,24 @@ public class GaussianBlur implements Task {
this.originalDst.copyTo(this.dst);
}
@Override
public void initDescription() {
switch (this.numParams) {
case 4:
this.descr = "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + ")";
break;
case 5:
this.descr = "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + +this.sigmaY + ")";
break;
case 6:
this.descr = "Imgproc.GaussianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + Objects.toString(this.ksize) + ", "
+ this.sigmaX + +this.sigmaY + this.borderType + ")";
break;
default:
throw new IllegalArgumentException();
}
}
}
@@ -27,6 +27,8 @@ public class MedianBlur implements Task {
private final Mat originalSrc;
private final Mat originalDst;
private String descr = "";
public MedianBlur(Mat src, Mat dst, int ksize) {
this.src = src;
this.dst = dst;
@@ -74,7 +76,7 @@ public class MedianBlur implements Task {
@Override
public String getDescription() {
return "Imgproc.medianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.ksize + ")";
return this.descr;
}
@Override
@@ -83,4 +85,9 @@ public class MedianBlur implements Task {
this.originalDst.copyTo(this.dst);
}
@Override
public void initDescription() {
this.descr = "Imgproc.medianBlur(" + Objects.toString(this.src) + ", " + Objects.toString(this.dst) + ", " + this.ksize + ")";
}
}
@@ -28,6 +28,8 @@ public class Resize implements Task {
private final Mat originalSrc;
private final Mat originalDst;
private String descr = "";
public Resize(Mat src, Mat dst, Size dsize) {
this.numParams = 3;
this.src = src;
@@ -153,18 +155,7 @@ public class Resize implements Task {
@Override
public String getDescription() {
switch (this.numParams) {
case 3:
return "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ")";
case 4:
return "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ")";
case 5:
return "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ", " + this.fy + ")";
case 6:
return "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ", " + this.fy + ", " + this.interpolation + ")";
default:
throw new RuntimeException();
}
return this.descr;
}
@Override
@@ -173,4 +164,24 @@ public class Resize implements Task {
this.originalDst.copyTo(this.dst);
}
@Override
public void initDescription() {
switch (this.numParams) {
case 3:
this.descr = "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ")";
break;
case 4:
this.descr = "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ")";
break;
case 5:
this.descr = "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ", " + this.fy + ")";
break;
case 6:
this.descr = "Imgproc.resize(" + this.src + ", " + this.dst + ", " + this.dsize + ", " + this.fx + ", " + this.fy + ", " + this.interpolation + ")";
break;
default:
throw new RuntimeException();
}
}
}
@@ -25,6 +25,8 @@ public class Threshold implements Task {
private final Mat originalSrc;
private final Mat originalDst;
private String descr = "";
public Threshold(Mat src, Mat dst, double thresh, double maxval, int type) {
this.src = src;
@@ -71,7 +73,7 @@ public class Threshold implements Task {
@Override
public String getDescription() {
return "Imgproc.threshold(" + this.src + ", " + this.dst + ", " + this.thresh + ", " + this.maxval + ", " + this.type + ")";
return this.descr;
}
@Override
@@ -80,4 +82,9 @@ public class Threshold implements Task {
this.originalDst.copyTo(this.dst);
}
@Override
public void initDescription() {
this.descr = "Imgproc.threshold(" + this.src + ", " + this.dst + ", " + this.thresh + ", " + this.maxval + ", " + this.type + ")";
}
}
@@ -16,6 +16,8 @@ public class Clone implements Task {
private final Mat _this;
private final Mat clone;
private String descr = "";
public Clone(Mat _this) {
this._this = _this;
this.clone = _this.clone();
@@ -54,7 +56,7 @@ public class Clone implements Task {
@Override
public String getDescription() {
return this._this + ".clone()";
return this.descr;
}
@Override
@@ -66,4 +68,8 @@ public class Clone implements Task {
return this.clone;
}
}
@Override
public void initDescription() {
this.descr = this._this + ".clone()";
}
}
@@ -19,6 +19,8 @@ public class CopyTo implements Task {
private final Mat original_this;
private final Mat originalM;
private String descr = "";
public CopyTo(Mat _this, Mat m) {
this._this = _this;
this.m = m;
@@ -64,7 +66,7 @@ public class CopyTo implements Task {
@Override
public String getDescription() {
return this._this + ".copyTo(" + this.m + ")";
return this.descr;
}
@Override
@@ -73,4 +75,9 @@ public class CopyTo implements Task {
this.originalM.copyTo(this.m);
}
@Override
public void initDescription() {
this.descr = this._this + ".copyTo(" + this.m + ")";
}
}
@@ -15,6 +15,8 @@ public class ORB_create implements Task {
private final float scaleFactor;
private String descr = "";
public ORB_create(int id) {
this.numParams = 0;
this.nfeatures = -1;
@@ -101,16 +103,7 @@ public class ORB_create implements Task {
@Override
public String getDescription() {
switch (this.numParams) {
case 0:
return "ORB.create()";
case 1:
return "ORB.create(" + this.nfeatures + ")";
case 2:
return "ORB.create(" + this.nfeatures + ", " + this.scaleFactor + ")";
default:
throw new RuntimeException();
}
return this.descr;
}
@Override
@@ -118,4 +111,21 @@ public class ORB_create implements Task {
}
@Override
public void initDescription() {
switch (this.numParams) {
case 0:
this.descr = "ORB.create()";
break;
case 1:
this.descr = "ORB.create(" + this.nfeatures + ")";
break;
case 2:
this.descr = "ORB.create(" + this.nfeatures + ", " + this.scaleFactor + ")";
break;
default:
throw new RuntimeException();
}
}
}
@@ -30,6 +30,8 @@ public class ORB_detectAndCompute implements Task {
private final MatOfKeyPoint originalKeypoints;
private final Mat originalDescriptors;
private String descr = "";
public ORB_detectAndCompute(int id, Mat image, Mat mask, MatOfKeyPoint keypoints, Mat descriptors) {
this.id = id;
@@ -125,7 +127,7 @@ public class ORB_detectAndCompute implements Task {
@Override
public String getDescription() {
return "ORB.detectAndCompute(" + this.image + ", " + this.mask + ", " + this.keypoints + ", " + this.descriptors + ")";
return this.descr;
}
@Override
@@ -136,4 +138,9 @@ public class ORB_detectAndCompute implements Task {
this.originalDescriptors.copyTo(this.descriptors);
}
@Override
public void initDescription() {
this.descr = "ORB.detectAndCompute(" + this.image + ", " + this.mask + ", " + this.keypoints + ", " + this.descriptors + ")";
}
}
@@ -26,6 +26,8 @@ public class StereoBM_compute implements Task {
private final Mat originalRight;
private final Mat originalDisparity;
private String descr = "";
public StereoBM_compute(int id, Mat left, Mat right, Mat disparity) {
this.id = id;
this.theMatcher = StereoBMs.getById(id);
@@ -81,7 +83,7 @@ public class StereoBM_compute implements Task {
@Override
public String getDescription() {
return "StereoBM.compute(" + this.left + ", " + this.right + ", " + this.disparity + ")";
return this.descr;
}
@Override
@@ -91,4 +93,9 @@ public class StereoBM_compute implements Task {
this.originalDisparity.copyTo(this.disparity);
}
@Override
public void initDescription() {
this.descr = "StereoBM.compute(" + this.left + ", " + this.right + ", " + this.disparity + ")";
}
}
@@ -18,6 +18,8 @@ public class StereoBM_create implements Task {
private final int blockSize;
private String descr = "";
public StereoBM_create(int id) {
this.numParams = 0;
this.numDisparities = -1;
@@ -98,16 +100,7 @@ public class StereoBM_create implements Task {
@Override
public String getDescription() {
switch (this.numParams) {
case 0:
return "StereoBM.create()";
case 1:
return "StereoBM.create(" + this.numDisparities + ")";
case 2:
return "StereoBM.create(" + this.numDisparities + ", " + this.blockSize + ")";
default:
throw new RuntimeException();
}
return this.descr;
}
@Override
@@ -115,4 +108,21 @@ public class StereoBM_create implements Task {
// Nothing to reset
}
@Override
public void initDescription() {
switch (this.numParams) {
case 0:
this.descr = "StereoBM.create()";
break;
case 1:
this.descr = "StereoBM.create(" + this.numDisparities + ")";
break;
case 2:
this.descr = "StereoBM.create(" + this.numDisparities + ", " + this.blockSize + ")";
break;
default:
throw new RuntimeException();
}
}
}
@@ -64,7 +64,6 @@ public class Imgproc {
public static void resize(Mat src, Mat dst, Size dsize, double fx, double fy) {
TestPipeline.INSTANCE.addTask(new Resize(src, dst, dsize, fx, fy));
}
public static void resize(Mat src, Mat dst, Size dsize, double fx, double fy, int interpolation) {
@@ -7,10 +7,13 @@ import org.opencv.highgui.HighGui;
public class DebugTask implements Task {
private Mat[] mats;
private final Mat[] mats;
private String descr;
public DebugTask(Mat... mats) {
this.mats = mats;
this.descr = "";
}
@Override
@@ -30,7 +33,7 @@ public class DebugTask implements Task {
@Override
public String getDescription() {
return "Debug task showing mats " + Arrays.toString(this.mats);
return this.descr;
}
@Override
@@ -38,4 +41,9 @@ public class DebugTask implements Task {
}
@Override
public void initDescription() {
this.descr = "Debug task showing mats " + Arrays.toString(this.mats);
}
}
@@ -14,10 +14,13 @@ public class DummyTask implements Task {
private static final CpuTask NOOP_CPU = () -> {
};
private Mat[] mats;
private final Mat[] mats;
private String descr;
public DummyTask(Mat... mats) {
this.mats = mats;
this.descr = "";
}
@Override
@@ -32,7 +35,7 @@ public class DummyTask implements Task {
@Override
public String getDescription() {
return "Dummy task containing mats: " + Arrays.toString(this.mats);
return this.descr;
}
@Override
@@ -40,4 +43,9 @@ public class DummyTask implements Task {
// nothing to reset
}
@Override
public void initDescription() {
this.descr = "Dummy task containing mats: " + Arrays.toString(this.mats);
}
}
@@ -14,4 +14,6 @@ public interface Task {
String getDescription();
void reset();
void initDescription();
}