From eb2f8a29486b8446dbcf6f35a894f5fb4e9cc63f Mon Sep 17 00:00:00 2001
From: Ilya Lavrenov <ilya.lavrenov@itseez.com>
Date: Fri, 25 Oct 2013 18:48:39 +0400
Subject: [PATCH] ocl tests: show diff when cv::countNonZero(diff) > 0

---
 modules/ocl/test/utility.cpp | 20 ++++++++++++--------
 modules/ocl/test/utility.hpp |  2 +-
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/modules/ocl/test/utility.cpp b/modules/ocl/test/utility.cpp
index 43dbac68c..b755ab36e 100644
--- a/modules/ocl/test/utility.cpp
+++ b/modules/ocl/test/utility.cpp
@@ -231,21 +231,25 @@ double checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vector<Rect>& o
     return final_test_result;
 }
 
-void showDiff(const Mat& gold, const Mat& actual, double eps)
+void showDiff(const Mat& gold, const Mat& actual, double eps, bool alwaysShow)
 {
     Mat diff;
     absdiff(gold, actual, diff);
+    diff.convertTo(diff, CV_32F);
     threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
 
-    namedWindow("gold", WINDOW_NORMAL);
-    namedWindow("actual", WINDOW_NORMAL);
-    namedWindow("diff", WINDOW_NORMAL);
+    if (alwaysShow || cv::countNonZero(diff.reshape(1)) > 0)
+    {
+        namedWindow("gold", WINDOW_NORMAL);
+        namedWindow("actual", WINDOW_NORMAL);
+        namedWindow("diff", WINDOW_NORMAL);
 
-    imshow("gold", gold);
-    imshow("actual", actual);
-    imshow("diff", diff);
+        imshow("gold", gold);
+        imshow("actual", actual);
+        imshow("diff", diff);
 
-    waitKey();
+        waitKey();
+    }
 }
 
 } // namespace cvtest
diff --git a/modules/ocl/test/utility.hpp b/modules/ocl/test/utility.hpp
index 5ad97b08a..47da0134d 100644
--- a/modules/ocl/test/utility.hpp
+++ b/modules/ocl/test/utility.hpp
@@ -52,7 +52,7 @@ extern int LOOP_TIMES;
 
 namespace cvtest {
 
-void showDiff(const Mat& gold, const Mat& actual, double eps);
+void showDiff(const Mat& gold, const Mat& actual, double eps, bool alwaysShow = false);
 
 cv::ocl::oclMat createMat_ocl(cv::RNG& rng, Size size, int type, bool useRoi);
 cv::ocl::oclMat loadMat_ocl(cv::RNG& rng, const Mat& m, bool useRoi);