added test data for mean shift procedure
authorAlexey Spizhevoy <no@email>
Mon, 11 Oct 2010 14:27:28 +0000 (14:27 +0000)
committerAlexey Spizhevoy <no@email>
Mon, 11 Oct 2010 14:27:28 +0000 (14:27 +0000)
tests/gpu/src/meanshift.cpp

index 06bf9f9..3ac3790 100644 (file)
@@ -123,3 +123,104 @@ struct CV_GpuMeanShiftTest : public CvTest
 /////////////////////////////////////////////////////////////////////////////\r
 \r
 CV_GpuMeanShiftTest CV_GpuMeanShift_test;\r
+\r
+struct CV_GpuMeanShiftProcTest : public CvTest\r
+{\r
+    CV_GpuMeanShiftProcTest(): CvTest( "GPU-MeanShiftProc", "MeanShiftProc" ){}\r
+\r
+    void run(int)\r
+    {\r
+        int spatialRad = 30;\r
+        int colorRad = 30;\r
+\r
+        cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png");\r
+\r
+        if (img.empty())\r
+        {\r
+            ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);\r
+            return;\r
+        }\r
+\r
+        cv::Mat rgba;\r
+        cvtColor(img, rgba, CV_BGR2BGRA);\r
+\r
+        try\r
+        {\r
+            cv::gpu::GpuMat h_rmap_filtered;\r
+            cv::gpu::meanShiftFiltering( cv::gpu::GpuMat(rgba), h_rmap_filtered, spatialRad, colorRad );\r
+\r
+            cv::gpu::GpuMat d_rmap;\r
+            cv::gpu::GpuMat d_spmap;\r
+            cv::gpu::meanShiftProc( cv::gpu::GpuMat(rgba), d_rmap, d_spmap, spatialRad, colorRad );\r
+\r
+            if (d_rmap.type() != CV_8UC4)\r
+            {\r
+                ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+                return;\r
+            }\r
+\r
+            cv::Mat rmap_filtered;\r
+            h_rmap_filtered.download(rmap_filtered);\r
+\r
+            cv::Mat rmap;\r
+            d_rmap.download(rmap);\r
+\r
+            uchar maxDiff = 0;\r
+            for (int j = 0; j < rmap_filtered.rows; ++j)\r
+            {\r
+                const uchar* res_line = rmap_filtered.ptr<uchar>(j);\r
+                const uchar* ref_line = rmap.ptr<uchar>(j);\r
+\r
+                for (int i = 0; i < rmap_filtered.cols; ++i)\r
+                {\r
+                    for (int k = 0; k < 3; ++k)\r
+                    {\r
+                        const uchar& ch1 = res_line[rmap_filtered.channels()*i + k];\r
+                        const uchar& ch2 = ref_line[rmap.channels()*i + k];\r
+                        uchar diff = static_cast<uchar>(abs(ch1 - ch2));\r
+                        if (maxDiff < diff)\r
+                            maxDiff = diff;\r
+                    }\r
+                }\r
+            }\r
+            if (maxDiff > 0) \r
+            {\r
+                ts->printf(CvTS::LOG, "\nMeanShiftProc maxDiff = %d\n", maxDiff);\r
+                ts->set_failed_test_info(CvTS::FAIL_GENERIC);\r
+                return;\r
+            }\r
+\r
+            cv::Mat spmap;\r
+            d_spmap.download(spmap);\r
+\r
+            cv::Mat spmap_template;\r
+            cv::FileStorage fs(std::string(ts->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ);\r
+            fs["spmap"] >> spmap_template;\r
+\r
+            for (int y = 0; y < spmap.rows; ++y) {\r
+                for (int x = 0; x < spmap.cols; ++x) {\r
+                    cv::Point_<short> expected = spmap_template.at<cv::Point_<short> >(y, x);\r
+                    cv::Point_<short> actual = spmap.at<cv::Point_<short> >(y, x);\r
+                    int diff = (expected - actual).dot(expected - actual);\r
+                    if (actual != expected) {\r
+                        ts->printf(CvTS::LOG, "\nMeanShiftProc SpMap is bad, diff=%d\n", diff);\r
+                        ts->set_failed_test_info(CvTS::FAIL_GENERIC);\r
+                        return;\r
+                    }\r
+                }\r
+            }\r
+\r
+        }\r
+        catch(const cv::Exception& e)\r
+        {\r
+            if (!check_and_treat_gpu_exception(e, ts))\r
+                throw;\r
+            return;\r
+        }\r
+\r
+        ts->set_failed_test_info(CvTS::OK);\r
+    }\r
+\r
+};\r
+\r
+CV_GpuMeanShiftProcTest CV_GpuMeanShiftProc_test;\r