Fixed java tests build
[profile/ivi/opencv.git] / modules / java / android_test / src / org / opencv / test / features2d / BRIEFDescriptorExtractorTest.java
1 package org.opencv.test.features2d;
2
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;
14
15 public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {
16
17     DescriptorExtractor extractor;
18     int matSize;
19
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);
24
25         return cross;
26     }
27
28     @Override
29     protected void setUp() throws Exception {
30         super.setUp();
31         extractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
32         matSize = 100;
33     }
34
35     public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
36         fail("Not yet implemented");
37     }
38
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();
44
45         extractor.compute(img, keypoints, descriptors);
46
47         Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
48             {
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);
53             }
54         };
55
56         assertMatEqual(truth, descriptors);
57     }
58
59     public void testCreate() {
60         assertNotNull(extractor);
61     }
62
63     public void testDescriptorSize() {
64         assertEquals(32, extractor.descriptorSize());
65     }
66
67     public void testDescriptorType() {
68         assertEquals(CvType.CV_8U, extractor.descriptorType());
69     }
70
71     public void testEmpty() {
72         assertFalse(extractor.empty());
73     }
74
75     public void testRead() {
76         String filename = OpenCVTestRunner.getTempFileName("yml");
77         writeFile(filename, "%YAML:1.0\ndescriptorSize: 64\n");
78
79         extractor.read(filename);
80
81         assertEquals(64, extractor.descriptorSize());
82     }
83
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
93     public void testWriteYml() {
94         String filename = OpenCVTestRunner.getTempFileName("yml");
95
96         extractor.write(filename);
97
98         String truth = "%YAML:1.0\ndescriptorSize: 32\n";
99         assertEquals(truth, readFile(filename));
100     }
101
102 }