Fixed findCirclesGrid for the case of working with 'square' asymmetric patterns.
authorIlya Lysenkov <no@email>
Wed, 13 Jul 2011 13:05:41 +0000 (13:05 +0000)
committerIlya Lysenkov <no@email>
Wed, 13 Jul 2011 13:05:41 +0000 (13:05 +0000)
modules/calib3d/src/calibinit.cpp
modules/calib3d/src/circlesgrid.cpp

index 04392a2..362b62f 100644 (file)
@@ -1939,8 +1939,8 @@ void cv::drawChessboardCorners( InputOutputArray _image, Size patternSize,
 bool cv::findCirclesGrid( InputArray _image, Size patternSize,
                           OutputArray _centers, int flags, const Ptr<FeatureDetector> &blobDetector )
 {
-       bool isAsymmetricGrid = (flags & CALIB_CB_ASYMMETRIC_GRID) ? true : false;
-       bool isSymmetricGrid  = (flags & CALIB_CB_SYMMETRIC_GRID ) ? true : false;
+    bool isAsymmetricGrid = (flags & CALIB_CB_ASYMMETRIC_GRID) ? true : false;
+    bool isSymmetricGrid  = (flags & CALIB_CB_SYMMETRIC_GRID ) ? true : false;
     CV_Assert(isAsymmetricGrid ^ isSymmetricGrid);
 
     Mat image = _image.getMat();
index 3982bf1..36fecba 100644 (file)
@@ -748,7 +748,13 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const vector<Point2f>&
   const Point2f offset(150, 150);
 
   vector<Point2f> dstPoints;
-  for (int i = 0; i < detectedGridSize.height; i++)
+  bool isClockwiseBefore =
+      getDirection(centers[0], centers[detectedGridSize.width - 1], centers[centers.size() - 1]) < 0;
+
+  int iStart = isClockwiseBefore ? 0 : detectedGridSize.height - 1;
+  int iEnd = isClockwiseBefore ? detectedGridSize.height : -1;
+  int iStep = isClockwiseBefore ? 1 : -1;
+  for (int i = iStart; i != iEnd; i += iStep)
   {
     for (int j = 0; j < detectedGridSize.width; j++)
     {
@@ -1453,6 +1459,10 @@ void CirclesGridFinder::getCornerSegments(const vector<vector<size_t> > &points,
     cout << "Corners are counterclockwise" << endl;
 #endif
     std::reverse(segments.begin(), segments.end());
+    std::reverse(cornerIndices.begin(), cornerIndices.end());
+    std::reverse(firstSteps.begin(), firstSteps.end());
+    std::reverse(secondSteps.begin(), secondSteps.end());
+    std::swap(firstSteps, secondSteps);
   }
 }