1 package org.opencv.test.features2d; 2 3 import org.opencv.core.CvType; 4 import org.opencv.core.Mat; 5 import org.opencv.core.MatOfKeyPoint; 6 import org.opencv.core.Point; 7 import org.opencv.core.Scalar; 8 import org.opencv.core.KeyPoint; 9 import org.opencv.test.OpenCVTestCase; 10 import org.opencv.test.OpenCVTestRunner; 11 import org.opencv.imgproc.Imgproc; 12 import org.opencv.features2d.Feature2D; 13 14 public class BRIEFDescriptorExtractorTest extends OpenCVTestCase { 15 16 Feature2D extractor; 17 int matSize; 18 getTestImg()19 private Mat getTestImg() { 20 Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); 21 Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2); 22 Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2); 23 24 return cross; 25 } 26 27 @Override setUp()28 protected void setUp() throws Exception { 29 super.setUp(); 30 extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null); 31 matSize = 100; 32 } 33 testComputeListOfMatListOfListOfKeyPointListOfMat()34 public void testComputeListOfMatListOfListOfKeyPointListOfMat() { 35 fail("Not yet implemented"); 36 } 37 testComputeMatListOfKeyPointMat()38 public void testComputeMatListOfKeyPointMat() { 39 KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); 40 MatOfKeyPoint keypoints = new MatOfKeyPoint(point); 41 Mat img = getTestImg(); 42 Mat descriptors = new Mat(); 43 44 extractor.compute(img, keypoints, descriptors); 45 46 Mat truth = new Mat(1, 32, CvType.CV_8UC1) { 47 { 48 put(0, 0, 96, 0, 76, 24, 47, 182, 68, 137, 49 149, 195, 67, 16, 187, 224, 74, 8, 50 82, 169, 87, 70, 44, 4, 192, 56, 51 13, 128, 44, 106, 146, 72, 194, 245); 52 } 53 }; 54 55 assertMatEqual(truth, descriptors); 56 } 57 testCreate()58 public void testCreate() { 59 assertNotNull(extractor); 60 } 61 testDescriptorSize()62 public void testDescriptorSize() { 63 assertEquals(32, extractor.descriptorSize()); 64 } 65 testDescriptorType()66 public void testDescriptorType() { 67 assertEquals(CvType.CV_8U, extractor.descriptorType()); 68 } 69 testEmpty()70 public void testEmpty() { 71 // assertFalse(extractor.empty()); 72 fail("Not yet implemented"); // BRIEF does not override empty() method 73 } 74 testRead()75 public void testRead() { 76 String filename = OpenCVTestRunner.getTempFileName("yml"); 77 writeFile(filename, "%YAML:1.0\n---\ndescriptorSize: 64\n"); 78 79 extractor.read(filename); 80 81 assertEquals(64, extractor.descriptorSize()); 82 } 83 testWrite()84 public void testWrite() { 85 String filename = OpenCVTestRunner.getTempFileName("xml"); 86 87 extractor.write(filename); 88 89 String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<descriptorSize>32</descriptorSize>\n</opencv_storage>\n"; 90 assertEquals(truth, readFile(filename)); 91 } 92 testWriteYml()93 public void testWriteYml() { 94 String filename = OpenCVTestRunner.getTempFileName("yml"); 95 96 extractor.write(filename); 97 98 String truth = "%YAML:1.0\n---\ndescriptorSize: 32\n"; 99 assertEquals(truth, readFile(filename)); 100 } 101 102 } 103