added implementation for ORB related functions
This commit is contained in:
+83
-6
@@ -9,31 +9,108 @@ import de.unidue.nes.gpu.testframework.tasks.Task;
|
||||
*/
|
||||
public class ORB_create implements Task {
|
||||
|
||||
public ORB_create(int id) {
|
||||
private final int numParams;
|
||||
|
||||
private final int nfeatures;
|
||||
|
||||
private final float scaleFactor;
|
||||
|
||||
public ORB_create(int id) {
|
||||
this.numParams = 0;
|
||||
this.nfeatures = -1;
|
||||
this.scaleFactor = -1;
|
||||
ORBs.addORB(org.opencv.features2d.ORB.create(500, 1.2f), id);
|
||||
ORBs.addCudaORB(org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(500, 1.2f, 8, 31, 0, 2, org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20, true), id);
|
||||
}
|
||||
|
||||
public ORB_create(int id, int nfeatures) {
|
||||
|
||||
this.numParams = 1;
|
||||
this.nfeatures = nfeatures;
|
||||
this.scaleFactor = -1;
|
||||
ORBs.addORB(org.opencv.features2d.ORB.create(nfeatures, 1.2f), id);
|
||||
ORBs.addCudaORB(
|
||||
org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(nfeatures, 1.2f, 8, 31, 0, 2, org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20, true), id);
|
||||
}
|
||||
|
||||
public ORB_create(int id, int nfeatures, float scaleFactor) {
|
||||
|
||||
this.numParams = 2;
|
||||
this.nfeatures = nfeatures;
|
||||
this.scaleFactor = scaleFactor;
|
||||
ORBs.addORB(org.opencv.features2d.ORB.create(nfeatures, scaleFactor), id);
|
||||
ORBs.addCudaORB(
|
||||
org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(nfeatures, scaleFactor, 8, 31, 0, 2, org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20, true),
|
||||
id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CpuTask toCpuTask() {
|
||||
return null;
|
||||
return () -> {
|
||||
switch (this.numParams) {
|
||||
case 0:
|
||||
org.opencv.features2d.ORB.create();
|
||||
break;
|
||||
case 1:
|
||||
org.opencv.features2d.ORB.create(this.nfeatures);
|
||||
break;
|
||||
case 2:
|
||||
org.opencv.features2d.ORB.create(this.nfeatures, this.scaleFactor);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public GpuTask toGpuTask() {
|
||||
return null;
|
||||
return new GpuTask() {
|
||||
|
||||
private org.bytedeco.opencv.opencv_cudafeatures2d.ORB theOrb;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (ORB_create.this.numParams) {
|
||||
case 0:
|
||||
this.theOrb = org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(500, 1.2f, 8, 31, 0, 2, org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20,
|
||||
true);
|
||||
break;
|
||||
case 1:
|
||||
this.theOrb = org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(ORB_create.this.nfeatures, 1.2f, 8, 31, 0, 2,
|
||||
org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20, true);
|
||||
break;
|
||||
case 2:
|
||||
this.theOrb = org.bytedeco.opencv.opencv_cudafeatures2d.ORB.create(ORB_create.this.nfeatures, ORB_create.this.scaleFactor, 8, 31, 0, 2,
|
||||
org.opencv.features2d.ORB.HARRIS_SCORE, 31, 20, true);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// Nothing to init
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
this.theOrb.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+103
-5
@@ -1,8 +1,12 @@
|
||||
package de.unidue.nes.gpu.testframework.internal.tasks.orb;
|
||||
|
||||
import org.bytedeco.opencv.opencv_core.GpuMat;
|
||||
import org.bytedeco.opencv.opencv_core.KeyPointVector;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.features2d.ORB;
|
||||
|
||||
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;
|
||||
@@ -12,28 +16,122 @@ import de.unidue.nes.gpu.testframework.tasks.Task;
|
||||
*/
|
||||
public class ORB_detectAndCompute implements Task {
|
||||
|
||||
public ORB_detectAndCompute(int id, Mat image, Mat mask, MatOfKeyPoint keypoints, Mat descriptors) {
|
||||
private final int id;
|
||||
|
||||
private final ORB theOrb;
|
||||
|
||||
private final Mat image;
|
||||
private final Mat mask;
|
||||
private final MatOfKeyPoint keypoints;
|
||||
private final Mat descriptors;
|
||||
|
||||
private final Mat originalImage;
|
||||
private final Mat originalMask;
|
||||
private final MatOfKeyPoint originalKeypoints;
|
||||
private final Mat originalDescriptors;
|
||||
|
||||
public ORB_detectAndCompute(int id, Mat image, Mat mask, MatOfKeyPoint keypoints, Mat descriptors) {
|
||||
this.id = id;
|
||||
|
||||
this.theOrb = ORBs.getById(this.id);
|
||||
|
||||
this.image = image;
|
||||
this.mask = mask;
|
||||
this.keypoints = keypoints;
|
||||
this.descriptors = descriptors;
|
||||
|
||||
this.originalImage = new Mat();
|
||||
this.image.copyTo(this.originalImage);
|
||||
|
||||
this.originalMask = new Mat();
|
||||
this.mask.copyTo(this.originalMask);
|
||||
|
||||
this.originalKeypoints = new MatOfKeyPoint();
|
||||
this.keypoints.copyTo(this.originalKeypoints);
|
||||
|
||||
this.originalDescriptors = new Mat();
|
||||
this.descriptors.copyTo(this.originalDescriptors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CpuTask toCpuTask() {
|
||||
return null;
|
||||
return () -> this.theOrb.detectAndCompute(this.image, this.mask, this.keypoints, this.descriptors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GpuTask toGpuTask() {
|
||||
return null;
|
||||
org.bytedeco.opencv.opencv_cudafeatures2d.ORB cudaOrb = ORBs.getCudaOrbById(this.id);
|
||||
if (cudaOrb == null) {
|
||||
return null;// no orb was created
|
||||
}
|
||||
return new GpuTask() {
|
||||
|
||||
private GpuMat gpuImage;
|
||||
|
||||
private GpuMat gpuMask;
|
||||
|
||||
private KeyPointVector keypointsAsJavaCVKeyPointVector;
|
||||
|
||||
private GpuMat gpuDescriptors;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
cudaOrb.detectAndCompute(this.gpuImage, this.gpuMask, this.keypointsAsJavaCVKeyPointVector, this.gpuDescriptors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
this.gpuImage = MatPool.getUploadedGpuMat(ORB_detectAndCompute.this.image, ORB_detectAndCompute.this);
|
||||
this.gpuMask = MatPool.getUploadedGpuMat(ORB_detectAndCompute.this.mask, ORB_detectAndCompute.this);
|
||||
this.gpuDescriptors = MatPool.getUploadedGpuMat(ORB_detectAndCompute.this.descriptors, ORB_detectAndCompute.this);
|
||||
|
||||
this.keypointsAsJavaCVKeyPointVector = createKeyPointVector(ORB_detectAndCompute.this.keypoints);
|
||||
|
||||
}
|
||||
|
||||
private KeyPointVector createKeyPointVector(MatOfKeyPoint keypoints) {
|
||||
org.opencv.core.KeyPoint[] opencvKeypoints = keypoints.toArray();
|
||||
org.bytedeco.opencv.opencv_core.KeyPoint[] javacvKeyPoints = new org.bytedeco.opencv.opencv_core.KeyPoint[opencvKeypoints.length];
|
||||
for (int i = 0; i < opencvKeypoints.length; i++) {
|
||||
org.opencv.core.KeyPoint kp = opencvKeypoints[i];
|
||||
org.bytedeco.opencv.opencv_core.KeyPoint javacvKeyPoint = new org.bytedeco.opencv.opencv_core.KeyPoint((float) kp.pt.x, (float) kp.pt.y,
|
||||
kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
|
||||
javacvKeyPoints[i] = javacvKeyPoint;
|
||||
}
|
||||
return new KeyPointVector(javacvKeyPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
copyKeyPointVectorToKeypoints(this.keypointsAsJavaCVKeyPointVector, ORB_detectAndCompute.this.keypoints);
|
||||
this.keypointsAsJavaCVKeyPointVector.close();
|
||||
}
|
||||
|
||||
private void copyKeyPointVectorToKeypoints(KeyPointVector vec, MatOfKeyPoint keypoints) {
|
||||
org.bytedeco.opencv.opencv_core.KeyPoint[] javacvKeyPoints = vec.get();
|
||||
org.opencv.core.KeyPoint[] opencvKeypoints = new org.opencv.core.KeyPoint[javacvKeyPoints.length];
|
||||
for (int i = 0; i < javacvKeyPoints.length; i++) {
|
||||
org.bytedeco.opencv.opencv_core.KeyPoint kp = javacvKeyPoints[i];
|
||||
org.opencv.core.KeyPoint opencvKeyPoint = new org.opencv.core.KeyPoint(kp.pt().x(), kp.pt().y(), kp.size(), kp.angle(), kp.response(),
|
||||
kp.octave(), kp.class_id());
|
||||
opencvKeypoints[i] = opencvKeyPoint;
|
||||
}
|
||||
keypoints.fromArray(opencvKeypoints);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
return "ORB.detectAndCompute(" + this.image + ", " + this.mask + ", " + this.keypoints + ", " + this.descriptors + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
|
||||
this.originalImage.copyTo(this.image);
|
||||
this.originalMask.copyTo(this.mask);
|
||||
this.originalKeypoints.copyTo(this.keypoints);
|
||||
this.originalDescriptors.copyTo(this.descriptors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,43 @@
|
||||
package de.unidue.nes.gpu.testframework.internal.tasks.orb;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class ORBs {
|
||||
|
||||
private static final Map<Integer, org.opencv.features2d.ORB> ORB_MAP = new HashMap<>();
|
||||
|
||||
private static final Map<Integer, org.bytedeco.opencv.opencv_cudafeatures2d.ORB> CUDA_ORB_MAP = new HashMap<>();
|
||||
|
||||
public static void addORB(org.opencv.features2d.ORB orb, int id) {
|
||||
if (ORB_MAP.containsKey(id)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
ORB_MAP.put(id, orb);
|
||||
}
|
||||
|
||||
public static void addCudaORB(org.bytedeco.opencv.opencv_cudafeatures2d.ORB orb, int id) {
|
||||
if (CUDA_ORB_MAP.containsKey(id)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
CUDA_ORB_MAP.put(id, orb);
|
||||
}
|
||||
|
||||
public static org.opencv.features2d.ORB getById(int id) {
|
||||
if (!ORB_MAP.containsKey(id)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return ORB_MAP.get(id);
|
||||
}
|
||||
|
||||
public static org.bytedeco.opencv.opencv_cudafeatures2d.ORB getCudaOrbById(int id) {
|
||||
if (!CUDA_ORB_MAP.containsKey(id)) {
|
||||
return null;
|
||||
}
|
||||
return CUDA_ORB_MAP.get(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user