1 package org.opencv.test.features2d;
3 import org.opencv.core.Core;
4 import org.opencv.core.CvType;
5 import org.opencv.core.Mat;
6 import org.opencv.core.MatOfKeyPoint;
7 import org.opencv.core.Point;
8 import org.opencv.core.Scalar;
9 import org.opencv.features2d.DescriptorExtractor;
10 import org.opencv.core.KeyPoint;
11 import org.opencv.test.OpenCVTestCase;
12 import org.opencv.test.OpenCVTestRunner;
13 import org.opencv.imgproc.Imgproc;
15 public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {
17 DescriptorExtractor extractor;
20 private Mat getTestImg() {
21 Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
22 Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
23 Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
29 protected void setUp() throws Exception {
31 extractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
35 public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
36 fail("Not yet implemented");
39 public void testComputeMatListOfKeyPointMat() {
40 KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
41 MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
42 Mat img = getTestImg();
43 Mat descriptors = new Mat();
45 extractor.compute(img, keypoints, descriptors);
47 Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
49 put(0, 0, 96, 0, 76, 24, 47, 182, 68, 137,
50 149, 195, 67, 16, 187, 224, 74, 8,
51 82, 169, 87, 70, 44, 4, 192, 56,
52 13, 128, 44, 106, 146, 72, 194, 245);
56 assertMatEqual(truth, descriptors);
59 public void testCreate() {
60 assertNotNull(extractor);
63 public void testDescriptorSize() {
64 assertEquals(32, extractor.descriptorSize());
67 public void testDescriptorType() {
68 assertEquals(CvType.CV_8U, extractor.descriptorType());
71 public void testEmpty() {
72 assertFalse(extractor.empty());
75 public void testRead() {
76 String filename = OpenCVTestRunner.getTempFileName("yml");
77 writeFile(filename, "%YAML:1.0\ndescriptorSize: 64\n");
79 extractor.read(filename);
81 assertEquals(64, extractor.descriptorSize());
84 public void testWrite() {
85 String filename = OpenCVTestRunner.getTempFileName("xml");
87 extractor.write(filename);
89 String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<descriptorSize>32</descriptorSize>\n</opencv_storage>\n";
90 assertEquals(truth, readFile(filename));
93 public void testWriteYml() {
94 String filename = OpenCVTestRunner.getTempFileName("yml");
96 extractor.write(filename);
98 String truth = "%YAML:1.0\ndescriptorSize: 32\n";
99 assertEquals(truth, readFile(filename));