increased singularity epsilon in LU decomposition. This solved singular case from...
authorVadim Pisarevsky <vadim.pisarevsky@gmail.com>
Thu, 14 May 2015 07:42:55 +0000 (10:42 +0300)
committerVadim Pisarevsky <vadim.pisarevsky@gmail.com>
Thu, 14 May 2015 07:42:55 +0000 (10:42 +0300)
modules/hal/src/matrix.cpp
modules/imgproc/test/test_imgwarp.cpp

index 9506aaf..921b778 100644 (file)
@@ -49,7 +49,7 @@ namespace cv { namespace hal {
 \****************************************************************************************/
 
 template<typename _Tp> static inline int
-LUImpl(_Tp* A, size_t astep, int m, _Tp* b, size_t bstep, int n)
+LUImpl(_Tp* A, size_t astep, int m, _Tp* b, size_t bstep, int n, _Tp eps)
 {
     int i, j, k, p = 1;
     astep /= sizeof(A[0]);
@@ -63,7 +63,7 @@ LUImpl(_Tp* A, size_t astep, int m, _Tp* b, size_t bstep, int n)
             if( std::abs(A[j*astep + i]) > std::abs(A[k*astep + i]) )
                 k = j;
 
-        if( std::abs(A[k*astep + i]) < std::numeric_limits<_Tp>::epsilon() )
+        if( std::abs(A[k*astep + i]) < eps )
             return 0;
 
         if( k != i )
@@ -111,13 +111,13 @@ LUImpl(_Tp* A, size_t astep, int m, _Tp* b, size_t bstep, int n)
 
 int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n)
 {
-    return LUImpl(A, astep, m, b, bstep, n);
+    return LUImpl(A, astep, m, b, bstep, n, FLT_EPSILON*10);
 }
 
 
 int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n)
 {
-    return LUImpl(A, astep, m, b, bstep, n);
+    return LUImpl(A, astep, m, b, bstep, n, DBL_EPSILON*100);
 }
 
 
index 9fa48de..d15f72e 100644 (file)
@@ -1654,4 +1654,18 @@ TEST(Imgproc_Warp, multichannel)
     }
 }
 
+TEST(Imgproc_GetAffineTransform, singularity)
+{
+    Point2f A_sample[3];
+    A_sample[0] = cv::Point2f(8, 9);
+    A_sample[1] = cv::Point2f(40, 41);
+    A_sample[2] = cv::Point2f(47, 48);
+    Point2f B_sample[3];
+    B_sample[0] = cv::Point2f(7.37465, 11.8295);
+    B_sample[1] = cv::Point2f(15.0113, 12.8994);
+    B_sample[2] = cv::Point2f(38.9943, 9.56297);
+    Mat trans = cv::getAffineTransform(A_sample, B_sample);
+    ASSERT_EQ(0.0, norm(trans, NORM_INF));
+}
+
 /* End of file. */