From: Andrey Kamaev Date: Thu, 4 Aug 2011 09:56:10 +0000 (+0000) Subject: Implemented read/write methods for BriefDescriptorExtractor class X-Git-Tag: accepted/2.0/20130307.220821~2167 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13185ad8f715b32a154a4a53a3f9a15866dfc0b7;p=profile%2Fivi%2Fopencv.git Implemented read/write methods for BriefDescriptorExtractor class --- diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 16d7e80..548b8c0 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -2052,6 +2052,9 @@ public: // bytes is a length of descriptor in bytes. It can be equal 16, 32 or 64 bytes. BriefDescriptorExtractor( int bytes = 32 ); + virtual void read( const FileNode& ); + virtual void write( FileStorage& ) const; + virtual int descriptorSize() const; virtual int descriptorType() const; diff --git a/modules/features2d/src/brief.cpp b/modules/features2d/src/brief.cpp index bde3127..29b5148 100644 --- a/modules/features2d/src/brief.cpp +++ b/modules/features2d/src/brief.cpp @@ -188,6 +188,31 @@ int BriefDescriptorExtractor::descriptorType() const return CV_8UC1; } +void BriefDescriptorExtractor::read( const FileNode& fn) +{ + int descriptorSize = fn["descriptorSize"]; + switch (descriptorSize) + { + case 16: + test_fn_ = pixelTests16; + break; + case 32: + test_fn_ = pixelTests32; + break; + case 64: + test_fn_ = pixelTests64; + break; + default: + CV_Error(CV_StsBadArg, "descriptorSize must be 16, 32, or 64"); + } + bytes_ = descriptorSize; +} + +void BriefDescriptorExtractor::write( FileStorage& fs) const +{ + fs << "descriptorSize" << bytes_; +} + void BriefDescriptorExtractor::computeImpl(const Mat& image, std::vector& keypoints, Mat& descriptors) const { // Construct integral image for fast smoothing (box filter) diff --git a/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java index 1244a06..c7eeb71 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java @@ -69,27 +69,20 @@ public class BRIEFDescriptorExtractorTest extends OpenCVTestCase { } public void testRead() { - KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); - List keypoints = Arrays.asList(point); - Mat img = getTestImg(); - Mat descriptors = new Mat(); - String filename = OpenCVTestRunner.getTempFileName("yml"); - writeFile(filename, "%YAML:1.0\nnOctaves: 4\nnOctaveLayers: 2\nextended: 1\nupright: 0\n"); + writeFile(filename, "%YAML:1.0\ndescriptorSize: 64\n"); extractor.read(filename); - extractor.compute(img, keypoints, descriptors); - assertEquals(128, descriptors.cols()); + assertEquals(64, extractor.descriptorSize()); } public void testWrite() { String filename = OpenCVTestRunner.getTempFileName("xml"); extractor.write(filename); - //OpenCVTestRunner.Log("!!!!!!!" + readFile(filename)); - String truth = "\n!!!!\n\n"; + String truth = "\n\n32\n\n"; assertEquals(truth, readFile(filename)); } @@ -97,9 +90,8 @@ public class BRIEFDescriptorExtractorTest extends OpenCVTestCase { String filename = OpenCVTestRunner.getTempFileName("yml"); extractor.write(filename); - //OpenCVTestRunner.Log("!!!!!!!" + readFile(filename)); - String truth = "%YAML:1.0\n!!!"; + String truth = "%YAML:1.0\ndescriptorSize: 32\n"; assertEquals(truth, readFile(filename)); } diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java index 3a5b215..f913580 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java @@ -72,18 +72,12 @@ public class SURFDescriptorExtractorTest extends OpenCVTestCase { } public void testRead() { - KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); - List keypoints = Arrays.asList(point); - Mat img = getTestImg(); - Mat descriptors = new Mat(); - String filename = OpenCVTestRunner.getTempFileName("yml"); writeFile(filename, "%YAML:1.0\nnOctaves: 4\nnOctaveLayers: 2\nextended: 1\nupright: 0\n"); extractor.read(filename); - extractor.compute(img, keypoints, descriptors); - assertEquals(128, descriptors.cols()); + assertEquals(128, extractor.descriptorSize()); } public void testWrite() {