From 6930325847f25e840ab70ec5cc2fc0e318ac1a8f Mon Sep 17 00:00:00 2001 From: atinfinity Date: Tue, 17 May 2016 22:57:05 +0900 Subject: [PATCH] Added test case of cv::threshold(CV_64F) --- modules/imgproc/test/test_thresh.cpp | 62 ++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/modules/imgproc/test/test_thresh.cpp b/modules/imgproc/test/test_thresh.cpp index f59fec19e1..529bff70da 100644 --- a/modules/imgproc/test/test_thresh.cpp +++ b/modules/imgproc/test/test_thresh.cpp @@ -56,8 +56,8 @@ protected: void prepare_to_validation( int ); int thresh_type; - float thresh_val; - float max_val; + double thresh_val; + double max_val; }; @@ -120,7 +120,7 @@ void CV_ThreshTest::run_func() static void test_threshold( const Mat& _src, Mat& _dst, - float thresh, float maxval, int thresh_type ) + double thresh, double maxval, int thresh_type ) { int i, j; int depth = _src.depth(), cn = _src.channels(); @@ -144,7 +144,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, imaxval = cvRound(maxval); } - assert( depth == CV_8U || depth == CV_16S || depth == CV_32F ); + assert( depth == CV_8U || depth == CV_16S || depth == CV_32F || depth == CV_64F ); switch( thresh_type ) { @@ -165,13 +165,20 @@ static void test_threshold( const Mat& _src, Mat& _dst, for( j = 0; j < width_n; j++ ) dst[j] = (short)(src[j] > ithresh ? imaxval : 0); } - else + else if( depth == CV_32F ) { const float* src = _src.ptr(i); float* dst = _dst.ptr(i); for( j = 0; j < width_n; j++ ) dst[j] = src[j] > thresh ? maxval : 0.f; } + else + { + const double* src = _src.ptr(i); + double* dst = _dst.ptr(i); + for( j = 0; j < width_n; j++ ) + dst[j] = src[j] > thresh ? maxval : 0.0; + } } break; case CV_THRESH_BINARY_INV: @@ -191,13 +198,20 @@ static void test_threshold( const Mat& _src, Mat& _dst, for( j = 0; j < width_n; j++ ) dst[j] = (short)(src[j] > ithresh ? 0 : imaxval); } - else + else if( depth == CV_32F ) { const float* src = _src.ptr(i); float* dst = _dst.ptr(i); for( j = 0; j < width_n; j++ ) dst[j] = src[j] > thresh ? 0.f : maxval; } + else + { + const double* src = _src.ptr(i); + double* dst = _dst.ptr(i); + for( j = 0; j < width_n; j++ ) + dst[j] = src[j] > thresh ? 0.0 : maxval; + } } break; case CV_THRESH_TRUNC: @@ -223,7 +237,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = (short)(s > ithresh ? ithresh2 : s); } } - else + else if( depth == CV_32F ) { const float* src = _src.ptr(i); float* dst = _dst.ptr(i); @@ -233,6 +247,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = s > thresh ? thresh : s; } } + else + { + const double* src = _src.ptr(i); + double* dst = _dst.ptr(i); + for( j = 0; j < width_n; j++ ) + { + double s = src[j]; + dst[j] = s > thresh ? thresh : s; + } + } } break; case CV_THRESH_TOZERO: @@ -258,7 +282,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = (short)(s > ithresh ? s : 0); } } - else + else if( depth == CV_32F ) { const float* src = _src.ptr(i); float* dst = _dst.ptr(i); @@ -268,6 +292,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = s > thresh ? s : 0.f; } } + else + { + const double* src = _src.ptr(i); + double* dst = _dst.ptr(i); + for( j = 0; j < width_n; j++ ) + { + double s = src[j]; + dst[j] = s > thresh ? s : 0.0; + } + } } break; case CV_THRESH_TOZERO_INV: @@ -293,7 +327,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = (short)(s > ithresh ? 0 : s); } } - else + else if (depth == CV_32F) { const float* src = _src.ptr(i); float* dst = _dst.ptr(i); @@ -303,6 +337,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, dst[j] = s > thresh ? 0.f : s; } } + else + { + const double* src = _src.ptr(i); + double* dst = _dst.ptr(i); + for( j = 0; j < width_n; j++ ) + { + double s = src[j]; + dst[j] = s > thresh ? 0.0 : s; + } + } } break; default: -- GitLab