fixed warpAffine and warpPerspective under Linux
authorAlexey Spizhevoy <no@email>
Fri, 11 Feb 2011 14:31:20 +0000 (14:31 +0000)
committerAlexey Spizhevoy <no@email>
Fri, 11 Feb 2011 14:31:20 +0000 (14:31 +0000)
tests/gpu/src/imgproc_gpu.cpp

index 10db183..8d2b678 100644 (file)
@@ -64,7 +64,10 @@ protected:
 \r
     virtual int test(const Mat& img) = 0;\r
 \r
-    int CheckNorm(const Mat& m1, const Mat& m2);  \r
+    int CheckNorm(const Mat& m1, const Mat& m2);\r
+\r
+    // Checks whether two images are similar enough using normalized\r
+    // cross-correlation as an error measure\r
     int CheckSimilarity(const Mat& m1, const Mat& m2, float max_err=1e-3f);\r
 };\r
 \r
@@ -97,7 +100,7 @@ int CV_GpuImageProcTest::test32SC1(const Mat& img)
 int CV_GpuImageProcTest::test32FC1(const Mat& img)\r
 {\r
     cv::Mat temp, img_C1;\r
-    img.convertTo(temp, CV_32F);\r
+    img.convertTo(temp, CV_32F, 1.f / 255.f);\r
     cvtColor(temp, img_C1, CV_BGR2GRAY);\r
 \r
     return test(img_C1);\r
@@ -317,12 +320,12 @@ struct CV_GpuNppImageWarpAffineTest : public CV_GpuImageProcTest
             return CvTS::OK;\r
         }\r
 \r
-        static const double coeffs[2][3] =\r
-        {\r
-            {cos(3.14 / 6), -sin(3.14 / 6), 100.0},\r
-            {sin(3.14 / 6), cos(3.14 / 6), -100.0}\r
-        };\r
-        Mat M(2, 3, CV_64F, (void*)coeffs);\r
+        static double reflect[2][3] = { {-1, 0, 0},\r
+                                        { 0, -1, 0} };\r
+        reflect[0][2] = img.cols;\r
+        reflect[1][2] = img.rows;\r
+\r
+        Mat M(2, 3, CV_64F, (void*)reflect);\r
 \r
         int flags[] = {INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_NEAREST | WARP_INVERSE_MAP, INTER_LINEAR | WARP_INVERSE_MAP, INTER_CUBIC | WARP_INVERSE_MAP};\r
         const char* flags_str[] = {"INTER_NEAREST", "INTER_LINEAR", "INTER_CUBIC", "INTER_NEAREST | WARP_INVERSE_MAP", "INTER_LINEAR | WARP_INVERSE_MAP", "INTER_CUBIC | WARP_INVERSE_MAP"};\r
@@ -341,7 +344,9 @@ struct CV_GpuNppImageWarpAffineTest : public CV_GpuImageProcTest
             GpuMat gpudst;\r
             cv::gpu::warpAffine(gpu1, gpudst, M, gpu1.size(), flags[i]);\r
 \r
-            if (CheckSimilarity(cpudst, gpudst, 3e-3f) != CvTS::OK)\r
+            // Check inner parts (ignoring 1 pixel width border)\r
+            if (CheckSimilarity(cpudst.rowRange(1, cpudst.rows - 1).colRange(1, cpudst.cols - 1),\r
+                                gpudst.rowRange(1, gpudst.rows - 1).colRange(1, gpudst.cols - 1)) != CvTS::OK)\r
                 test_res = CvTS::FAIL_GENERIC;\r
         }\r
 \r
@@ -364,13 +369,12 @@ struct CV_GpuNppImageWarpPerspectiveTest : public CV_GpuImageProcTest
             return CvTS::OK;\r
         }\r
 \r
-        static const double coeffs[3][3] =\r
-        {\r
-            {cos(3.14 / 6), -sin(3.14 / 6), 100.0},\r
-            {sin(3.14 / 6), cos(3.14 / 6), -100.0},\r
-            {0.0, 0.0, 1.0}\r
-        };\r
-        Mat M(3, 3, CV_64F, (void*)coeffs);\r
+        static double reflect[3][3] = { { -1, 0, 0},\r
+                                        { 0, -1, 0},\r
+                                        { 0, 0, 1 }};\r
+        reflect[0][2] = img.cols;\r
+        reflect[1][2] = img.rows;\r
+        Mat M(3, 3, CV_64F, (void*)reflect);\r
 \r
         int flags[] = {INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_NEAREST | WARP_INVERSE_MAP, INTER_LINEAR | WARP_INVERSE_MAP, INTER_CUBIC | WARP_INVERSE_MAP};\r
         const char* flags_str[] = {"INTER_NEAREST", "INTER_LINEAR", "INTER_CUBIC", "INTER_NEAREST | WARP_INVERSE_MAP", "INTER_LINEAR | WARP_INVERSE_MAP", "INTER_CUBIC | WARP_INVERSE_MAP"};\r
@@ -389,7 +393,9 @@ struct CV_GpuNppImageWarpPerspectiveTest : public CV_GpuImageProcTest
             GpuMat gpudst;\r
             cv::gpu::warpPerspective(gpu1, gpudst, M, gpu1.size(), flags[i]);\r
 \r
-            if (CheckSimilarity(cpudst, gpudst, 3e-3f) != CvTS::OK)\r
+            // Check inner parts (ignoring 1 pixel width border)\r
+            if (CheckSimilarity(cpudst.rowRange(1, cpudst.rows - 1).colRange(1, cpudst.cols - 1),\r
+                                gpudst.rowRange(1, gpudst.rows - 1).colRange(1, gpudst.cols - 1)) != CvTS::OK)\r
                 test_res = CvTS::FAIL_GENERIC;\r
         }\r
 \r