Path: blob/master/modules/features2d/misc/java/test/BRIEFDescriptorExtractorTest.java
16354 views
package org.opencv.test.features2d;12import org.opencv.core.CvType;3import org.opencv.core.Mat;4import org.opencv.core.MatOfKeyPoint;5import org.opencv.core.Point;6import org.opencv.core.Scalar;7import org.opencv.core.KeyPoint;8import org.opencv.test.OpenCVTestCase;9import org.opencv.test.OpenCVTestRunner;10import org.opencv.imgproc.Imgproc;11import org.opencv.features2d.Feature2D;1213public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {1415Feature2D extractor;16int matSize;1718private Mat getTestImg() {19Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));20Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);21Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);2223return cross;24}2526@Override27protected void setUp() throws Exception {28super.setUp();29extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null);30matSize = 100;31}3233public void testComputeListOfMatListOfListOfKeyPointListOfMat() {34fail("Not yet implemented");35}3637public void testComputeMatListOfKeyPointMat() {38KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);39MatOfKeyPoint keypoints = new MatOfKeyPoint(point);40Mat img = getTestImg();41Mat descriptors = new Mat();4243extractor.compute(img, keypoints, descriptors);4445Mat truth = new Mat(1, 32, CvType.CV_8UC1) {46{47put(0, 0, 96, 0, 76, 24, 47, 182, 68, 137,48149, 195, 67, 16, 187, 224, 74, 8,4982, 169, 87, 70, 44, 4, 192, 56,5013, 128, 44, 106, 146, 72, 194, 245);51}52};5354assertMatEqual(truth, descriptors);55}5657public void testCreate() {58assertNotNull(extractor);59}6061public void testDescriptorSize() {62assertEquals(32, extractor.descriptorSize());63}6465public void testDescriptorType() {66assertEquals(CvType.CV_8U, extractor.descriptorType());67}6869public void testEmpty() {70// assertFalse(extractor.empty());71fail("Not yet implemented"); // BRIEF does not override empty() method72}7374public void testRead() {75String filename = OpenCVTestRunner.getTempFileName("yml");76writeFile(filename, "%YAML:1.0\n---\ndescriptorSize: 64\n");7778extractor.read(filename);7980assertEquals(64, extractor.descriptorSize());81}8283public void testWrite() {84String filename = OpenCVTestRunner.getTempFileName("xml");8586extractor.write(filename);8788String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<descriptorSize>32</descriptorSize>\n</opencv_storage>\n";89assertEquals(truth, readFile(filename));90}9192public void testWriteYml() {93String filename = OpenCVTestRunner.getTempFileName("yml");9495extractor.write(filename);9697String truth = "%YAML:1.0\n---\ndescriptorSize: 32\n";98assertEquals(truth, readFile(filename));99}100101}102103104