feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
102
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BRIEFDescriptorExtractorTest.java
vendored
Normal file
102
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BRIEFDescriptorExtractorTest.java
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D extractor;
|
||||
int matSize;
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null);
|
||||
matSize = 100;
|
||||
}
|
||||
|
||||
public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComputeMatListOfKeyPointMat() {
|
||||
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
|
||||
Mat img = getTestImg();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
|
||||
{
|
||||
put(0, 0, 96, 0, 76, 24, 47, 182, 68, 137,
|
||||
149, 195, 67, 16, 187, 224, 74, 8,
|
||||
82, 169, 87, 70, 44, 4, 192, 56,
|
||||
13, 128, 44, 106, 146, 72, 194, 245);
|
||||
}
|
||||
};
|
||||
|
||||
assertMatEqual(truth, descriptors);
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(extractor);
|
||||
}
|
||||
|
||||
public void testDescriptorSize() {
|
||||
assertEquals(32, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testDescriptorType() {
|
||||
assertEquals(CvType.CV_8U, extractor.descriptorType());
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(extractor.empty());
|
||||
fail("Not yet implemented"); // BRIEF does not override empty() method
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\ndescriptorSize: 64\n");
|
||||
|
||||
extractor.read(filename);
|
||||
|
||||
assertEquals(64, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<descriptorSize>32</descriptorSize>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\ndescriptorSize: 32\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
304
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceDescriptorMatcherTest.java
vendored
Normal file
304
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceDescriptorMatcherTest.java
vendored
Normal file
@ -0,0 +1,304 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.features2d.BFMatcher;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BruteForceDescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(5, 2, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
Mat img = getQueryImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "nOctaveLayers", "int", 4);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(30, matSize / 2), new Point(matSize - 31, matSize / 2), new Scalar(100), 3);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 30), new Point(matSize / 2, matSize - 31), new Scalar(100), 3);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
Mat img = getTrainImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1));
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
|
||||
matSize = 100;
|
||||
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 0.6159003f),
|
||||
new DMatch(1, 1, 0, 0.9177120f),
|
||||
new DMatch(2, 1, 0, 0.3112163f),
|
||||
new DMatch(3, 1, 0, 0.2925074f),
|
||||
new DMatch(4, 1, 0, 0.26520672f)
|
||||
};
|
||||
}
|
||||
|
||||
// https://github.com/opencv/opencv/issues/11268
|
||||
public void testConstructor()
|
||||
{
|
||||
BFMatcher self_created_matcher = new BFMatcher();
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
self_created_matcher.add(Arrays.asList(train));
|
||||
assertTrue(!self_created_matcher.empty());
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone();
|
||||
|
||||
assertNotNull(cloned);
|
||||
|
||||
List<Mat> descriptors = cloned.getTrainDescriptors();
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertTrue(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
final int k = 3;
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
List<MatOfDMatch> matches = new ArrayList<MatOfDMatch>();
|
||||
matcher.knnMatch(query, train, matches, k);
|
||||
/*
|
||||
Log.d("knnMatch", "train = " + train);
|
||||
Log.d("knnMatch", "query = " + query);
|
||||
|
||||
matcher.add(train);
|
||||
matcher.knnMatch(query, matches, k);
|
||||
*/
|
||||
assertEquals(query.rows(), matches.size());
|
||||
for(int i = 0; i<matches.size(); i++)
|
||||
{
|
||||
MatOfDMatch vdm = matches.get(i);
|
||||
//Log.d("knn", "vdm["+i+"]="+vdm.dump());
|
||||
assertTrue(Math.min(k, train.rows()) >= vdm.total());
|
||||
for(DMatch dm : vdm.toArray())
|
||||
{
|
||||
assertEquals(dm.queryIdx, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
|
||||
// OpenCVTestRunner.Log("matches found: " + matches.size());
|
||||
// for (DMatch m : matches)
|
||||
// OpenCVTestRunner.Log(m.toString());
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\n");
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);// BruteforceMatcher has no settings
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
matcher.train();// BruteforceMatcher does not need to train
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
262
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceHammingDescriptorMatcherTest.java
vendored
Normal file
262
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceHammingDescriptorMatcherTest.java
vendored
Normal file
@ -0,0 +1,262 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.features2d.FastFeatureDetector;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BruteForceHammingDescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(4, 4, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
return getTestDescriptors(getQueryImg());
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(img, new Point(40, matSize - 40), new Point(matSize - 50, 50), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
private Mat getTestDescriptors(Mat img) {
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = FastFeatureDetector.create();
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
return getTestDescriptors(getTrainImg());
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(img, new Point(40, 40), new Point(matSize - 40, matSize - 40), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
|
||||
matSize = 100;
|
||||
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 51),
|
||||
new DMatch(1, 2, 0, 42),
|
||||
new DMatch(2, 1, 0, 40),
|
||||
new DMatch(3, 3, 0, 53) };
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone();
|
||||
|
||||
assertNotNull(cloned);
|
||||
|
||||
List<Mat> descriptors = cloned.getTrainDescriptors();
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertTrue(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
ArrayList<MatOfDMatch> matches = new ArrayList<MatOfDMatch>();
|
||||
|
||||
matcher.radiusMatch(query, train, matches, 50.f);
|
||||
|
||||
assertEquals(4, matches.size());
|
||||
assertTrue(matches.get(0).empty());
|
||||
assertMatEqual(matches.get(1), new MatOfDMatch(truth[1]), EPS);
|
||||
assertMatEqual(matches.get(2), new MatOfDMatch(truth[2]), EPS);
|
||||
assertTrue(matches.get(3).empty());
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\n");
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);// BruteforceMatcher has no settings
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
matcher.train();// BruteforceMatcher does not need to train
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,257 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.features2d.FastFeatureDetector;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BruteForceHammingLUTDescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(4, 4, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
return getTestDescriptors(getQueryImg());
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(img, new Point(40, matSize - 40), new Point(matSize - 50, 50), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
private Mat getTestDescriptors(Mat img) {
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = FastFeatureDetector.create();
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
return getTestDescriptors(getTrainImg());
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(img, new Point(40, 40), new Point(matSize - 40, matSize - 40), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
|
||||
matSize = 100;
|
||||
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 51),
|
||||
new DMatch(1, 2, 0, 42),
|
||||
new DMatch(2, 1, 0, 40),
|
||||
new DMatch(3, 3, 0, 53) };
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone();
|
||||
|
||||
assertNotNull(cloned);
|
||||
|
||||
List<Mat> descriptors = cloned.getTrainDescriptors();
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertTrue(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
/*
|
||||
OpenCVTestRunner.Log("matches found: " + matches.size());
|
||||
for (DMatch m : matches.toArray())
|
||||
OpenCVTestRunner.Log(m.toString());
|
||||
*/
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\n");
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);// BruteforceMatcher has no settings
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
matcher.train();// BruteforceMatcher does not need to train
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
268
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceL1DescriptorMatcherTest.java
vendored
Normal file
268
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceL1DescriptorMatcherTest.java
vendored
Normal file
@ -0,0 +1,268 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BruteForceL1DescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(5, 2, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
Mat img = getQueryImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
setProperty(detector, "extended", "boolean", true);
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaveLayers", "int", 2);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(30, matSize / 2), new Point(matSize - 31, matSize / 2), new Scalar(100), 3);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 30), new Point(matSize / 2, matSize - 31), new Scalar(100), 3);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
Mat img = getTrainImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1));
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_L1);
|
||||
matSize = 100;
|
||||
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 3.0710702f),
|
||||
new DMatch(1, 1, 0, 3.562016f),
|
||||
new DMatch(2, 1, 0, 1.3682679f),
|
||||
new DMatch(3, 1, 0, 1.3012862f),
|
||||
new DMatch(4, 1, 0, 1.1852086f)
|
||||
};
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone();
|
||||
|
||||
assertNotNull(cloned);
|
||||
|
||||
List<Mat> descriptors = cloned.getTrainDescriptors();
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertTrue(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\n");
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);// BruteforceMatcher has no settings
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
matcher.train();// BruteforceMatcher does not need to train
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
280
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceSL2DescriptorMatcherTest.java
vendored
Normal file
280
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/BruteForceSL2DescriptorMatcherTest.java
vendored
Normal file
@ -0,0 +1,280 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class BruteForceSL2DescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(5, 2, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
private float sqr(float val){
|
||||
return val * val;
|
||||
}
|
||||
*/
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
Mat img = getQueryImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "nOctaveLayers", "int", 4);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(30, matSize / 2), new Point(matSize - 31, matSize / 2), new Scalar(100), 3);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 30), new Point(matSize / 2, matSize - 31), new Scalar(100), 3);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
Mat img = getTrainImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1));
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_SL2);
|
||||
matSize = 100;
|
||||
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 0.37933317f),
|
||||
new DMatch(1, 1, 0, 0.8421953f),
|
||||
new DMatch(2, 1, 0, 0.0968556f),
|
||||
new DMatch(3, 1, 0, 0.0855606f),
|
||||
new DMatch(4, 1, 0, 0.07033461f)
|
||||
};
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone();
|
||||
|
||||
assertNotNull(cloned);
|
||||
|
||||
List<Mat> descriptors = cloned.getTrainDescriptors();
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertTrue(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches);
|
||||
OpenCVTestRunner.Log(matches);
|
||||
OpenCVTestRunner.Log(matches);
|
||||
OpenCVTestRunner.Log(matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
|
||||
// OpenCVTestRunner.Log("matches found: " + matches.size());
|
||||
// for (DMatch m : matches)
|
||||
// OpenCVTestRunner.Log(m.toString());
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth[0], truth[1]), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\n");
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);// BruteforceMatcher has no settings
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
matcher.train();// BruteforceMatcher does not need to train
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/DENSEFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/DENSEFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class DENSEFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
150
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/FASTFeatureDetectorTest.java
vendored
Normal file
150
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/FASTFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
import org.opencv.features2d.FastFeatureDetector;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
public class FASTFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D detector;
|
||||
KeyPoint[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
Mat mask = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
|
||||
Mat right = mask.submat(0, 100, 50, 100);
|
||||
right.setTo(new Scalar(0));
|
||||
return mask;
|
||||
}
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat img = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(img, new Point(30, 30), new Point(70, 70), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
detector = FastFeatureDetector.create();
|
||||
truth = new KeyPoint[] { new KeyPoint(32, 27, 7, -1, 254, 0, -1), new KeyPoint(27, 32, 7, -1, 254, 0, -1), new KeyPoint(73, 68, 7, -1, 254, 0, -1),
|
||||
new KeyPoint(68, 73, 7, -1, 254, 0, -1) };
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(detector);
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
Mat img = getTestImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
||||
|
||||
// OpenCVTestRunner.Log("points found: " + keypoints.size());
|
||||
// for (KeyPoint kp : keypoints)
|
||||
// OpenCVTestRunner.Log(kp.toString());
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
Mat img = getTestImg();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints, mask);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented"); //FAST does not override empty() method
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
writeFile(filename, "%YAML:1.0\n---\nthreshold: 130\nnonmaxSuppression: 1\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(grayChess, keypoints1);
|
||||
|
||||
writeFile(filename, "%YAML:1.0\n---\nthreshold: 150\nnonmaxSuppression: 1\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(grayChess, keypoints2);
|
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total());
|
||||
}
|
||||
|
||||
public void testReadYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
writeFile(filename,
|
||||
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(grayChess, keypoints1);
|
||||
|
||||
writeFile(filename,
|
||||
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(grayChess, keypoints2);
|
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.FAST</name>\n<nonmaxSuppression>1</nonmaxSuppression>\n<threshold>10</threshold>\n<type>2</type>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
String data = readFile(filename);
|
||||
//Log.d("qqq", "\"" + data + "\"");
|
||||
assertEquals(truth, data);
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
String data = readFile(filename);
|
||||
|
||||
//Log.d("qqq", "\"" + data + "\"");
|
||||
assertEquals(truth, data);
|
||||
}
|
||||
}
|
172
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/Features2dTest.java
vendored
Normal file
172
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/Features2dTest.java
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.calib3d.Calib3d;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Range;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.features2d.Features2d;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class Features2dTest extends OpenCVTestCase {
|
||||
|
||||
public void testDrawKeypointsMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawKeypointsMatListOfKeyPointMatScalar() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawKeypointsMatListOfKeyPointMatScalarInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatches2MatListOfKeyPointMatListOfKeyPointListOfListOfDMatchMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatches2MatListOfKeyPointMatListOfKeyPointListOfListOfDMatchMatScalar() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatches2MatListOfKeyPointMatListOfKeyPointListOfListOfDMatchMatScalarScalar() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatches2MatListOfKeyPointMatListOfKeyPointListOfListOfDMatchMatScalarScalarListOfListOfByte() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatches2MatListOfKeyPointMatListOfKeyPointListOfListOfDMatchMatScalarScalarListOfListOfByteInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatchesMatListOfKeyPointMatListOfKeyPointListOfDMatchMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatchesMatListOfKeyPointMatListOfKeyPointListOfDMatchMatScalar() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatchesMatListOfKeyPointMatListOfKeyPointListOfDMatchMatScalarScalar() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatchesMatListOfKeyPointMatListOfKeyPointListOfDMatchMatScalarScalarListOfByte() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDrawMatchesMatListOfKeyPointMatListOfKeyPointListOfDMatchMatScalarScalarListOfByteInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testPTOD()
|
||||
{
|
||||
String detectorCfg = "%YAML:1.0\n---\nhessianThreshold: 4000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n";
|
||||
String extractorCfg = "%YAML:1.0\n---\nnOctaves: 4\nnOctaveLayers: 2\nextended: 0\nupright: 0\n";
|
||||
|
||||
Feature2D detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
|
||||
|
||||
String detectorCfgFile = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(detectorCfgFile, detectorCfg);
|
||||
detector.read(detectorCfgFile);
|
||||
|
||||
String extractorCfgFile = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(extractorCfgFile, extractorCfg);
|
||||
extractor.read(extractorCfgFile);
|
||||
|
||||
Mat imgTrain = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.IMREAD_GRAYSCALE);
|
||||
Mat imgQuery = imgTrain.submat(new Range(0, imgTrain.rows() - 100), Range.all());
|
||||
|
||||
MatOfKeyPoint trainKeypoints = new MatOfKeyPoint();
|
||||
MatOfKeyPoint queryKeypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(imgTrain, trainKeypoints);
|
||||
detector.detect(imgQuery, queryKeypoints);
|
||||
|
||||
// OpenCVTestRunner.Log("Keypoints found: " + trainKeypoints.size() +
|
||||
// ":" + queryKeypoints.size());
|
||||
|
||||
Mat trainDescriptors = new Mat();
|
||||
Mat queryDescriptors = new Mat();
|
||||
|
||||
extractor.compute(imgTrain, trainKeypoints, trainDescriptors);
|
||||
extractor.compute(imgQuery, queryKeypoints, queryDescriptors);
|
||||
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.add(Arrays.asList(trainDescriptors));
|
||||
matcher.match(queryDescriptors, matches);
|
||||
|
||||
// OpenCVTestRunner.Log("Matches found: " + matches.size());
|
||||
|
||||
DMatch adm[] = matches.toArray();
|
||||
List<Point> lp1 = new ArrayList<Point>(adm.length);
|
||||
List<Point> lp2 = new ArrayList<Point>(adm.length);
|
||||
KeyPoint tkp[] = trainKeypoints.toArray();
|
||||
KeyPoint qkp[] = queryKeypoints.toArray();
|
||||
for (int i = 0; i < adm.length; i++) {
|
||||
DMatch dm = adm[i];
|
||||
lp1.add(tkp[dm.trainIdx].pt);
|
||||
lp2.add(qkp[dm.queryIdx].pt);
|
||||
}
|
||||
|
||||
MatOfPoint2f points1 = new MatOfPoint2f(lp1.toArray(new Point[0]));
|
||||
MatOfPoint2f points2 = new MatOfPoint2f(lp2.toArray(new Point[0]));
|
||||
|
||||
Mat hmg = Calib3d.findHomography(points1, points2, Calib3d.RANSAC, 3);
|
||||
|
||||
assertMatEqual(Mat.eye(3, 3, CvType.CV_64F), hmg, EPS);
|
||||
|
||||
Mat outimg = new Mat();
|
||||
Features2d.drawMatches(imgQuery, queryKeypoints, imgTrain, trainKeypoints, matches, outimg);
|
||||
String outputPath = OpenCVTestRunner.getOutputFileName("PTODresult.png");
|
||||
Imgcodecs.imwrite(outputPath, outimg);
|
||||
// OpenCVTestRunner.Log("Output image is saved to: " + outputPath);
|
||||
}
|
||||
|
||||
public void testDrawKeypoints()
|
||||
{
|
||||
Mat outImg = Mat.ones(11, 11, CvType.CV_8U);
|
||||
|
||||
MatOfKeyPoint kps = new MatOfKeyPoint(new KeyPoint(5, 5, 1)); // x, y, size
|
||||
Features2d.drawKeypoints(new Mat(), kps, outImg, new Scalar(255),
|
||||
Features2d.DrawMatchesFlags_DRAW_OVER_OUTIMG);
|
||||
|
||||
Mat ref = new MatOfInt(new int[] {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 15, 54, 15, 1, 1, 1, 1,
|
||||
1, 1, 1, 76, 217, 217, 221, 81, 1, 1, 1,
|
||||
1, 1, 100, 224, 111, 57, 115, 225, 101, 1, 1,
|
||||
1, 44, 215, 100, 1, 1, 1, 101, 214, 44, 1,
|
||||
1, 54, 212, 57, 1, 1, 1, 55, 212, 55, 1,
|
||||
1, 40, 215, 104, 1, 1, 1, 105, 215, 40, 1,
|
||||
1, 1, 102, 221, 111, 55, 115, 222, 103, 1, 1,
|
||||
1, 1, 1, 76, 218, 217, 220, 81, 1, 1, 1,
|
||||
1, 1, 1, 1, 15, 55, 15, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||
}).reshape(1, 11);
|
||||
ref.convertTo(ref, CvType.CV_8U);
|
||||
|
||||
assertMatEqual(ref, outImg);
|
||||
}
|
||||
}
|
389
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/FlannBasedDescriptorMatcherTest.java
vendored
Normal file
389
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/FlannBasedDescriptorMatcherTest.java
vendored
Normal file
@ -0,0 +1,389 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvException;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.features2d.DescriptorMatcher;
|
||||
import org.opencv.features2d.FlannBasedMatcher;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
|
||||
|
||||
static final String xmlParamsDefault = "<?xml version=\"1.0\"?>\n"
|
||||
+ "<opencv_storage>\n"
|
||||
+ "<format>3</format>\n"
|
||||
+ "<indexParams>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>algorithm</name>\n"
|
||||
+ " <type>9</type>\n" // FLANN_INDEX_TYPE_ALGORITHM
|
||||
+ " <value>1</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>trees</name>\n"
|
||||
+ " <type>4</type>\n"
|
||||
+ " <value>4</value></_></indexParams>\n"
|
||||
+ "<searchParams>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>checks</name>\n"
|
||||
+ " <type>4</type>\n"
|
||||
+ " <value>32</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>eps</name>\n"
|
||||
+ " <type>5</type>\n"
|
||||
+ " <value>0.</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>explore_all_trees</name>\n"
|
||||
+ " <type>8</type>\n"
|
||||
+ " <value>0</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>sorted</name>\n"
|
||||
+ " <type>8</type>\n" // FLANN_INDEX_TYPE_BOOL
|
||||
+ " <value>1</value></_></searchParams>\n"
|
||||
+ "</opencv_storage>\n";
|
||||
static final String ymlParamsDefault = "%YAML:1.0\n---\n"
|
||||
+ "format: 3\n"
|
||||
+ "indexParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: algorithm\n"
|
||||
+ " type: 9\n" // FLANN_INDEX_TYPE_ALGORITHM
|
||||
+ " value: 1\n"
|
||||
+ " -\n"
|
||||
+ " name: trees\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 4\n"
|
||||
+ "searchParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: checks\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 32\n"
|
||||
+ " -\n"
|
||||
+ " name: eps\n"
|
||||
+ " type: 5\n"
|
||||
+ " value: 0.\n"
|
||||
+ " -\n"
|
||||
+ " name: explore_all_trees\n"
|
||||
+ " type: 8\n"
|
||||
+ " value: 0\n"
|
||||
+ " -\n"
|
||||
+ " name: sorted\n"
|
||||
+ " type: 8\n" // FLANN_INDEX_TYPE_BOOL
|
||||
+ " value: 1\n";
|
||||
static final String ymlParamsModified = "%YAML:1.0\n---\n"
|
||||
+ "format: 3\n"
|
||||
+ "indexParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: algorithm\n"
|
||||
+ " type: 9\n" // FLANN_INDEX_TYPE_ALGORITHM
|
||||
+ " value: 6\n"// this line is changed!
|
||||
+ " -\n"
|
||||
+ " name: trees\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 4\n"
|
||||
+ "searchParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: checks\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 32\n"
|
||||
+ " -\n"
|
||||
+ " name: eps\n"
|
||||
+ " type: 5\n"
|
||||
+ " value: 4.\n"// this line is changed!
|
||||
+ " -\n"
|
||||
+ " name: explore_all_trees\n"
|
||||
+ " type: 8\n"
|
||||
+ " value: 1\n"// this line is changed!
|
||||
+ " -\n"
|
||||
+ " name: sorted\n"
|
||||
+ " type: 8\n" // FLANN_INDEX_TYPE_BOOL
|
||||
+ " value: 1\n";
|
||||
|
||||
DescriptorMatcher matcher;
|
||||
|
||||
int matSize;
|
||||
|
||||
DMatch[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
return new Mat(5, 2, CvType.CV_8U, new Scalar(0)) {
|
||||
{
|
||||
put(0, 0, 1, 1, 1, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getQueryDescriptors() {
|
||||
Mat img = getQueryImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getQueryImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(30, matSize / 2), new Point(matSize - 31, matSize / 2), new Scalar(100), 3);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 30), new Point(matSize / 2, matSize - 31), new Scalar(100), 3);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
private Mat getTrainDescriptors() {
|
||||
Mat img = getTrainImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1));
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
Feature2D extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getTrainImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
|
||||
matSize = 100;
|
||||
truth = new DMatch[] {
|
||||
new DMatch(0, 0, 0, 0.6159003f),
|
||||
new DMatch(1, 1, 0, 0.9177120f),
|
||||
new DMatch(2, 1, 0, 0.3112163f),
|
||||
new DMatch(3, 1, 0, 0.2925075f),
|
||||
new DMatch(4, 1, 0, 0.26520672f)
|
||||
};
|
||||
}
|
||||
|
||||
// https://github.com/opencv/opencv/issues/11268
|
||||
public void testConstructor()
|
||||
{
|
||||
FlannBasedMatcher self_created_matcher = new FlannBasedMatcher();
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
self_created_matcher.add(Arrays.asList(train));
|
||||
assertTrue(!self_created_matcher.empty());
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
assertFalse(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
matcher.clear();
|
||||
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
try {
|
||||
matcher.clone();
|
||||
fail("Expected CvException (CV_StsNotImplemented)");
|
||||
} catch (CvException cverr) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCloneBoolean() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
|
||||
DescriptorMatcher cloned = matcher.clone(true);
|
||||
|
||||
assertNotNull(cloned);
|
||||
assertTrue(cloned.empty());
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(matcher);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
assertTrue(matcher.empty());
|
||||
}
|
||||
|
||||
public void testGetTrainDescriptors() {
|
||||
Mat train = new Mat(1, 1, CvType.CV_8U, new Scalar(123));
|
||||
Mat truth = train.clone();
|
||||
matcher.add(Arrays.asList(train));
|
||||
|
||||
List<Mat> descriptors = matcher.getTrainDescriptors();
|
||||
|
||||
assertEquals(1, descriptors.size());
|
||||
assertMatEqual(truth, descriptors.get(0));
|
||||
}
|
||||
|
||||
public void testIsMaskSupported() {
|
||||
assertFalse(matcher.isMaskSupported());
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatListOfListOfDMatchIntListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testKnnMatchMatMatListOfListOfDMatchIntMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
matcher.train();
|
||||
|
||||
matcher.match(query, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatListOfDMatchListOfMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
matcher.add(Arrays.asList(train));
|
||||
matcher.train();
|
||||
|
||||
matcher.match(query, matches, Arrays.asList(mask));
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatch() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
|
||||
|
||||
// OpenCVTestRunner.Log(matches.toString());
|
||||
// OpenCVTestRunner.Log(matches);
|
||||
}
|
||||
|
||||
public void testMatchMatMatListOfDMatchMat() {
|
||||
Mat train = getTrainDescriptors();
|
||||
Mat query = getQueryDescriptors();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfDMatch matches = new MatOfDMatch();
|
||||
|
||||
matcher.match(query, train, matches, mask);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(truth), matches.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatListOfListOfDMatchFloatListOfMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRadiusMatchMatMatListOfListOfDMatchFloatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filenameR = OpenCVTestRunner.getTempFileName("yml");
|
||||
String filenameW = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filenameR, ymlParamsModified);
|
||||
|
||||
matcher.read(filenameR);
|
||||
matcher.write(filenameW);
|
||||
|
||||
assertEquals(ymlParamsModified, readFile(filenameW));
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
Mat train = getTrainDescriptors();
|
||||
matcher.add(Arrays.asList(train));
|
||||
matcher.train();
|
||||
}
|
||||
|
||||
public void testTrainNoData() {
|
||||
try {
|
||||
matcher.train();
|
||||
fail("Expected CvException - FlannBasedMatcher::train should fail on empty train set");
|
||||
} catch (CvException cverr) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
assertEquals(xmlParamsDefault, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
assertEquals(ymlParamsDefault, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/GFTTFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/GFTTFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class GFTTFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/HARRISFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/HARRISFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class HARRISFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/MSERFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/MSERFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class MSERFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
124
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/ORBDescriptorExtractorTest.java
vendored
Normal file
124
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/ORBDescriptorExtractorTest.java
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.features2d.ORB;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
public class ORBDescriptorExtractorTest extends OpenCVTestCase {
|
||||
|
||||
ORB extractor;
|
||||
int matSize;
|
||||
|
||||
public static void assertDescriptorsClose(Mat expected, Mat actual, int allowedDistance) {
|
||||
double distance = Core.norm(expected, actual, Core.NORM_HAMMING);
|
||||
assertTrue("expected:<" + allowedDistance + "> but was:<" + distance + ">", distance <= allowedDistance);
|
||||
}
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
extractor = ORB.create();
|
||||
matSize = 100;
|
||||
}
|
||||
|
||||
public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComputeMatListOfKeyPointMat() {
|
||||
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
|
||||
Mat img = getTestImg();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
|
||||
{
|
||||
put(0, 0,
|
||||
6, 74, 6, 129, 2, 130, 56, 0, 44, 132, 66, 165, 172, 6, 3, 72, 102, 61, 171, 214, 0, 144, 65, 232, 4, 32, 138, 131, 4, 21, 37, 217);
|
||||
}
|
||||
};
|
||||
assertDescriptorsClose(truth, descriptors, 1);
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(extractor);
|
||||
}
|
||||
|
||||
public void testDescriptorSize() {
|
||||
assertEquals(32, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testDescriptorType() {
|
||||
assertEquals(CvType.CV_8U, extractor.descriptorType());
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(extractor.empty());
|
||||
fail("Not yet implemented"); // ORB does not override empty() method
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
|
||||
Mat img = getTestImg();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
// String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
// writeFile(filename, "%YAML:1.0\n---\nscaleFactor: 1.1\nnLevels: 3\nfirstLevel: 0\nedgeThreshold: 31\npatchSize: 31\n");
|
||||
// extractor.read(filename);
|
||||
extractor = ORB.create(500, 1.1f, 3, 31, 0, 2, ORB.HARRIS_SCORE, 31, 20);
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
|
||||
{
|
||||
put(0, 0,
|
||||
6, 10, 22, 5, 2, 130, 56, 0, 44, 164, 66, 165, 140, 6, 1, 72, 38, 61, 163, 210, 0, 208, 1, 104, 4, 32, 74, 131, 0, 37, 37, 67);
|
||||
}
|
||||
};
|
||||
assertDescriptorsClose(truth, descriptors, 1);
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.ORB</name>\n<WTA_K>2</WTA_K>\n<edgeThreshold>31</edgeThreshold>\n<firstLevel>0</firstLevel>\n<nFeatures>500</nFeatures>\n<nLevels>8</nLevels>\n<patchSize>31</patchSize>\n<scaleFactor>1.2000000476837158e+00</scaleFactor>\n<scoreType>0</scoreType>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.ORB\"\nWTA_K: 2\nedgeThreshold: 31\nfirstLevel: 0\nnFeatures: 500\nnLevels: 8\npatchSize: 31\nscaleFactor: 1.2000000476837158e+00\nscoreType: 0\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class ORBFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
110
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIFTDescriptorExtractorTest.java
vendored
Normal file
110
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIFTDescriptorExtractorTest.java
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.features2d.SIFT;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D extractor;
|
||||
KeyPoint keypoint;
|
||||
int matSize;
|
||||
Mat truth;
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
extractor = SIFT.create();
|
||||
keypoint = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
||||
matSize = 100;
|
||||
truth = new Mat(1, 128, CvType.CV_32FC1) {
|
||||
{
|
||||
put(0, 0,
|
||||
0, 0, 0, 1, 3, 0, 0, 0, 15, 23, 22, 20, 24, 2, 0, 0, 7, 8, 2, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 16, 13, 2, 0, 0, 117,
|
||||
86, 79, 68, 117, 42, 5, 5, 79, 60, 117, 25, 9, 2, 28, 19, 11, 13,
|
||||
20, 2, 0, 0, 5, 8, 0, 0, 76, 58, 34, 31, 97, 16, 95, 49, 117, 92,
|
||||
117, 112, 117, 76, 117, 54, 117, 25, 29, 22, 117, 117, 16, 11, 14,
|
||||
1, 0, 0, 22, 26, 0, 0, 0, 0, 1, 4, 15, 2, 47, 8, 0, 0, 82, 56, 31,
|
||||
17, 81, 12, 0, 0, 26, 23, 18, 23, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComputeMatListOfKeyPointMat() {
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint);
|
||||
Mat img = getTestImg();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
assertMatEqual(truth, descriptors, EPS);
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(extractor);
|
||||
}
|
||||
|
||||
public void testDescriptorSize() {
|
||||
assertEquals(128, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testDescriptorType() {
|
||||
assertEquals(CvType.CV_32F, extractor.descriptorType());
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(extractor.empty());
|
||||
fail("Not yet implemented"); //SIFT does not override empty() method
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SIFT</name>\n<contrastThreshold>4.0000000000000001e-02</contrastThreshold>\n<edgeThreshold>10.</edgeThreshold>\n<nFeatures>0</nFeatures>\n<nOctaveLayers>3</nOctaveLayers>\n<sigma>1.6000000000000001e+00</sigma>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.SIFT\"\ncontrastThreshold: 4.0000000000000001e-02\nedgeThreshold: 10.\nnFeatures: 0\nnOctaveLayers: 3\nsigma: 1.6000000000000001e+00\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
String actual = readFile(filename);
|
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual);
|
||||
}
|
||||
|
||||
}
|
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIFTFeatureDetectorTest.java
vendored
Normal file
39
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIFTFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class SIFTFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
public void testCreate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
118
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIMPLEBLOBFeatureDetectorTest.java
vendored
Normal file
118
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SIMPLEBLOBFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
import org.opencv.features2d.SimpleBlobDetector;
|
||||
|
||||
public class SIMPLEBLOBFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D detector;
|
||||
int matSize;
|
||||
KeyPoint[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Mat right = mask.submat(0, matSize, matSize / 2, matSize);
|
||||
right.setTo(new Scalar(0));
|
||||
return mask;
|
||||
}
|
||||
|
||||
private Mat getTestImg() {
|
||||
|
||||
int center = matSize / 2;
|
||||
int offset = 40;
|
||||
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.circle(img, new Point(center - offset, center), 24, new Scalar(0), -1);
|
||||
Imgproc.circle(img, new Point(center + offset, center), 20, new Scalar(50), -1);
|
||||
Imgproc.circle(img, new Point(center, center - offset), 18, new Scalar(100), -1);
|
||||
Imgproc.circle(img, new Point(center, center + offset), 14, new Scalar(150), -1);
|
||||
Imgproc.circle(img, new Point(center, center), 10, new Scalar(200), -1);
|
||||
return img;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
detector = SimpleBlobDetector.create();
|
||||
matSize = 200;
|
||||
truth = new KeyPoint[] {
|
||||
new KeyPoint( 140, 100, 41.036568f, -1, 0, 0, -1),
|
||||
new KeyPoint( 60, 100, 48.538486f, -1, 0, 0, -1),
|
||||
new KeyPoint(100, 60, 36.769554f, -1, 0, 0, -1),
|
||||
new KeyPoint(100, 140, 28.635643f, -1, 0, 0, -1),
|
||||
new KeyPoint(100, 100, 20.880613f, -1, 0, 0, -1)
|
||||
};
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(detector);
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
Mat img = getTestImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
Mat img = getTestImg();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints, mask);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth[1]), keypoints.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
Mat img = getTestImg();
|
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||||
detector.detect(img, keypoints1);
|
||||
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\nthresholdStep: 10\nminThreshold: 50\nmaxThreshold: 220\nminRepeatability: 2\nfilterByArea: true\nminArea: 800\nmaxArea: 5000\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||||
detector.detect(img, keypoints2);
|
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<format>3</format>\n<thresholdStep>10.</thresholdStep>\n<minThreshold>50.</minThreshold>\n<maxThreshold>220.</maxThreshold>\n<minRepeatability>2</minRepeatability>\n<minDistBetweenBlobs>10.</minDistBetweenBlobs>\n<filterByColor>1</filterByColor>\n<blobColor>0</blobColor>\n<filterByArea>1</filterByArea>\n<minArea>25.</minArea>\n<maxArea>5000.</maxArea>\n<filterByCircularity>0</filterByCircularity>\n<minCircularity>8.0000001192092896e-01</minCircularity>\n<maxCircularity>3.4028234663852886e+38</maxCircularity>\n<filterByInertia>1</filterByInertia>\n<minInertiaRatio>1.0000000149011612e-01</minInertiaRatio>\n<maxInertiaRatio>3.4028234663852886e+38</maxInertiaRatio>\n<filterByConvexity>1</filterByConvexity>\n<minConvexity>9.4999998807907104e-01</minConvexity>\n<maxConvexity>3.4028234663852886e+38</maxConvexity>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
}
|
133
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/STARFeatureDetectorTest.java
vendored
Normal file
133
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/STARFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class STARFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D detector;
|
||||
int matSize;
|
||||
KeyPoint[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Mat right = mask.submat(0, matSize, matSize / 2, matSize);
|
||||
right.setTo(new Scalar(0));
|
||||
return mask;
|
||||
}
|
||||
|
||||
private Mat getTestImg() {
|
||||
Scalar color = new Scalar(0);
|
||||
int center = matSize / 2;
|
||||
int radius = 6;
|
||||
int offset = 40;
|
||||
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.circle(img, new Point(center - offset, center), radius, color, -1);
|
||||
Imgproc.circle(img, new Point(center + offset, center), radius, color, -1);
|
||||
Imgproc.circle(img, new Point(center, center - offset), radius, color, -1);
|
||||
Imgproc.circle(img, new Point(center, center + offset), radius, color, -1);
|
||||
Imgproc.circle(img, new Point(center, center), radius, color, -1);
|
||||
return img;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null);
|
||||
matSize = 200;
|
||||
truth = new KeyPoint[] {
|
||||
new KeyPoint( 95, 80, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint(105, 80, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint( 80, 95, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint(120, 95, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint(100, 100, 8, -1, 30.f, 0, -1),
|
||||
new KeyPoint( 80, 105, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint(120, 105, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint( 95, 120, 22, -1, 31.5957f, 0, -1),
|
||||
new KeyPoint(105, 120, 22, -1, 31.5957f, 0, -1)
|
||||
};
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(detector);
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
Mat img = getTestImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
Mat img = getTestImg();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints, mask);
|
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints.toList(), EPS);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
Mat img = getTestImg();
|
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||||
detector.detect(img, keypoints1);
|
||||
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||||
detector.detect(img, keypoints2);
|
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.STAR</name>\n<lineThresholdBinarized>8</lineThresholdBinarized>\n<lineThresholdProjected>10</lineThresholdProjected>\n<maxSize>45</maxSize>\n<responseThreshold>30</responseThreshold>\n<suppressNonmaxSize>5</suppressNonmaxSize>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.STAR\"\nlineThresholdBinarized: 8\nlineThresholdProjected: 10\nmaxSize: 45\nresponseThreshold: 30\nsuppressNonmaxSize: 5\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
119
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SURFDescriptorExtractorTest.java
vendored
Normal file
119
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SURFDescriptorExtractorTest.java
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class SURFDescriptorExtractorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D extractor;
|
||||
int matSize;
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Class[] cParams = {double.class, int.class, int.class, boolean.class, boolean.class};
|
||||
Object[] oValues = {100, 2, 4, true, false};
|
||||
extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, cParams, oValues);
|
||||
|
||||
matSize = 100;
|
||||
}
|
||||
|
||||
public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComputeMatListOfKeyPointMat() {
|
||||
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
|
||||
Mat img = getTestImg();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
Mat truth = new Mat(1, 128, CvType.CV_32FC1) {
|
||||
{
|
||||
put(0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0.058821894, 0.058821894, -0.045962855, 0.046261817, 0.0085156476,
|
||||
0.0085754395, -0.0064509804, 0.0064509804, 0.00044069235, 0.00044069235, 0, 0, 0.00025723741,
|
||||
0.00025723741, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00025723741, 0.00025723741, -0.00044069235,
|
||||
0.00044069235, 0, 0, 0.36278215, 0.36278215, -0.24688604, 0.26173124, 0.052068226, 0.052662034,
|
||||
-0.032815345, 0.032815345, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.0064523756,
|
||||
0.0064523756, 0.0082002236, 0.0088908644, -0.059001274, 0.059001274, 0.045789491, 0.04648013,
|
||||
0.11961588, 0.22789426, -0.01322381, 0.18291828, -0.14042182, 0.23973691, 0.073782086, 0.23769434,
|
||||
-0.027880307, 0.027880307, 0.049587864, 0.049587864, -0.33991757, 0.33991757, 0.21437603, 0.21437603,
|
||||
-0.0020763327, 0.0020763327, 0.006245892, 0.006245892, -0.04067041, 0.04067041, 0.019361559,
|
||||
0.019361559, 0, 0, -0.0035977389, 0.0035977389, 0, 0, -0.00099993451, 0.00099993451, 0.040670406,
|
||||
0.040670406, -0.019361559, 0.019361559, 0.006245892, 0.006245892, -0.0020763327, 0.0020763327,
|
||||
-0.00034532088, 0.00034532088, 0, 0, 0, 0, 0.00034532088, 0.00034532088, -0.00099993451,
|
||||
0.00099993451, 0, 0, 0, 0, 0.0035977389, 0.0035977389
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
assertMatEqual(truth, descriptors, EPS);
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(extractor);
|
||||
}
|
||||
|
||||
public void testDescriptorSize() {
|
||||
assertEquals(128, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testDescriptorType() {
|
||||
assertEquals(CvType.CV_32F, extractor.descriptorType());
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(extractor.empty());
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\nnOctaves: 4\nnOctaveLayers: 2\nextended: 1\nupright: 0\n");
|
||||
|
||||
extractor.read(filename);
|
||||
|
||||
assertEquals(128, extractor.descriptorSize());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SURF</name>\n<extended>1</extended>\n<hessianThreshold>100.</hessianThreshold>\n<nOctaveLayers>2</nOctaveLayers>\n<nOctaves>4</nOctaves>\n<upright>0</upright>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
extractor.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.SURF\"\nextended: 1\nhessianThreshold: 100.\nnOctaveLayers: 2\nnOctaves: 4\nupright: 0\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
175
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SURFFeatureDetectorTest.java
vendored
Normal file
175
3rdparty/opencv-4.5.4/modules/features2d/misc/java/test/SURFFeatureDetectorTest.java
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
package org.opencv.test.features2d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.test.OpenCVTestRunner;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.features2d.Feature2D;
|
||||
|
||||
public class SURFFeatureDetectorTest extends OpenCVTestCase {
|
||||
|
||||
Feature2D detector;
|
||||
int matSize;
|
||||
KeyPoint[] truth;
|
||||
|
||||
private Mat getMaskImg() {
|
||||
Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Mat right = mask.submat(0, matSize, matSize / 2, matSize);
|
||||
right.setTo(new Scalar(0));
|
||||
return mask;
|
||||
}
|
||||
|
||||
private Mat getTestImg() {
|
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
||||
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
private void order(List<KeyPoint> points) {
|
||||
Collections.sort(points, new Comparator<KeyPoint>() {
|
||||
public int compare(KeyPoint p1, KeyPoint p2) {
|
||||
if (p1.angle < p2.angle)
|
||||
return -1;
|
||||
if (p1.angle > p2.angle)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null);
|
||||
matSize = 100;
|
||||
truth = new KeyPoint[] {
|
||||
new KeyPoint(55.775578f, 55.775578f, 16, 80.245735f, 8617.8633f, 0, -1),
|
||||
new KeyPoint(44.224422f, 55.775578f, 16, 170.24574f, 8617.8633f, 0, -1),
|
||||
new KeyPoint(44.224422f, 44.224422f, 16, 260.24573f, 8617.8633f, 0, -1),
|
||||
new KeyPoint(55.775578f, 44.224422f, 16, 350.24573f, 8617.8633f, 0, -1)
|
||||
};
|
||||
}
|
||||
|
||||
public void testCreate() {
|
||||
assertNotNull(detector);
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "nOctaveLayers", "int", 4);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
List<MatOfKeyPoint> keypoints = new ArrayList<MatOfKeyPoint>();
|
||||
Mat cross = getTestImg();
|
||||
List<Mat> crosses = new ArrayList<Mat>(3);
|
||||
crosses.add(cross);
|
||||
crosses.add(cross);
|
||||
crosses.add(cross);
|
||||
|
||||
detector.detect(crosses, keypoints);
|
||||
|
||||
assertEquals(3, keypoints.size());
|
||||
|
||||
for (MatOfKeyPoint mkp : keypoints) {
|
||||
List<KeyPoint> lkp = mkp.toList();
|
||||
order(lkp);
|
||||
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPoint() {
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "nOctaveLayers", "int", 4);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
Mat cross = getTestImg();
|
||||
|
||||
detector.detect(cross, keypoints);
|
||||
|
||||
List<KeyPoint> lkp = keypoints.toList();
|
||||
order(lkp);
|
||||
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS);
|
||||
}
|
||||
|
||||
public void testDetectMatListOfKeyPointMat() {
|
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000);
|
||||
setProperty(detector, "nOctaves", "int", 3);
|
||||
setProperty(detector, "nOctaveLayers", "int", 4);
|
||||
setProperty(detector, "upright", "boolean", false);
|
||||
|
||||
Mat img = getTestImg();
|
||||
Mat mask = getMaskImg();
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||||
|
||||
detector.detect(img, keypoints, mask);
|
||||
|
||||
List<KeyPoint> lkp = keypoints.toList();
|
||||
order(lkp);
|
||||
assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), lkp, EPS);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
Mat cross = getTestImg();
|
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||||
detector.detect(cross, keypoints1);
|
||||
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n---\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n");
|
||||
detector.read(filename);
|
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||||
detector.detect(cross, keypoints2);
|
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total());
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SURF</name>\n<extended>0</extended>\n<hessianThreshold>100.</hessianThreshold>\n<nOctaveLayers>3</nOctaveLayers>\n<nOctaves>4</nOctaves>\n<upright>0</upright>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
detector.write(filename);
|
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.SURF\"\nextended: 0\nhessianThreshold: 100.\nnOctaveLayers: 3\nnOctaves: 4\nupright: 0\n";
|
||||
String truth = "%YAML:1.0\n---\n";
|
||||
assertEquals(truth, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user