Stitching: added grid option to OrbFeaturesFinder
authorAndrey Kamaev <no@email>
Fri, 21 Oct 2011 08:40:10 +0000 (08:40 +0000)
committerAndrey Kamaev <no@email>
Fri, 21 Oct 2011 08:40:10 +0000 (08:40 +0000)
modules/stitching/include/opencv2/stitching/detail/matchers.hpp
modules/stitching/src/matchers.cpp

index 665de73..674b4a5 100644 (file)
@@ -92,12 +92,13 @@ private:
 class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder\r
 {\r
 public:\r
-    OrbFeaturesFinder(size_t n_features = 1500, const ORB::CommonParams & detector_params = ORB::CommonParams(1.3, 5));\r
+    OrbFeaturesFinder(Size _grid_size = Size(4,4), size_t n_features = 1500, const ORB::CommonParams & detector_params = ORB::CommonParams(1.3, 5));\r
 \r
 private:\r
     void find(const Mat &image, ImageFeatures &features);\r
 \r
     Ptr<ORB> orb;\r
+    Size grid_size;\r
 };\r
 \r
 \r
index b1a2f84..ec6eac5 100644 (file)
@@ -337,9 +337,10 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
     }\r
 }\r
 \r
-OrbFeaturesFinder::OrbFeaturesFinder(size_t n_features, const ORB::CommonParams & detector_params)\r
+OrbFeaturesFinder::OrbFeaturesFinder(Size _grid_size, size_t n_features, const ORB::CommonParams & detector_params)\r
 {\r
-    orb = new ORB(n_features, detector_params);\r
+    grid_size = _grid_size;\r
+    orb = new ORB(n_features * (99 + grid_size.area())/100/grid_size.area(), detector_params);\r
 }\r
 \r
 void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features)\r
@@ -348,7 +349,36 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features)
     CV_Assert(image.type() == CV_8UC3);\r
     cvtColor(image, gray_image, CV_BGR2GRAY);\r
 \r
-    (*orb)(gray_image, Mat(), features.keypoints, features.descriptors);\r
+    if (grid_size.area() == 1)\r
+        (*orb)(gray_image, Mat(), features.keypoints, features.descriptors);\r
+    else\r
+    {\r
+        features.keypoints.clear();\r
+        features.descriptors.release();\r
+\r
+        std::vector<KeyPoint> points;\r
+        Mat descriptors;\r
+\r
+        for (int r = 0; r < grid_size.height; ++r)\r
+            for (int c = 0; c < grid_size.width; ++c)\r
+            {\r
+                int xl = c * gray_image.cols / grid_size.width;\r
+                int yl = r * gray_image.rows / grid_size.height;\r
+                int xr = (c+1) * gray_image.cols / grid_size.width;\r
+                int yr = (r+1) * gray_image.rows / grid_size.height;\r
+\r
+                (*orb)(gray_image(Range(yl, yr), Range(xl, xr)), Mat(), points, descriptors);\r
+\r
+                features.keypoints.reserve(features.keypoints.size() + points.size());\r
+                for (std::vector<KeyPoint>::iterator kp = points.begin(); kp != points.end(); ++kp)\r
+                {\r
+                    kp->pt.x += xl;\r
+                    kp->pt.y += yl;\r
+                    features.keypoints.push_back(*kp);\r
+                }\r
+                features.descriptors.push_back(descriptors);\r
+            }\r
+    }\r
 }\r
 \r
 #ifndef ANDROID\r