BRIEFDescriptorExtractorTest.java 3.1 KB

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