From 87f282eed27d65c8b8d604738612f55d2cf04bcc Mon Sep 17 00:00:00 2001 From: OpenCV Buildbot Date: Wed, 19 Sep 2012 16:49:39 +0400 Subject: [PATCH 1/2] update FFMPEG wrapper binaries --- 3rdparty/ffmpeg/opencv_ffmpeg.dll | Bin 9160844 -> 9160844 bytes 3rdparty/ffmpeg/opencv_ffmpeg_64.dll | Bin 9219038 -> 9219038 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/3rdparty/ffmpeg/opencv_ffmpeg.dll b/3rdparty/ffmpeg/opencv_ffmpeg.dll index a5e9e656ffdf23bca7b0a499aa98225d510344a2..53cc4113313af56712a5ca171a181a37dc0050ea 100644 GIT binary patch delta 653 zcmWm8$5K-P06ck_aqBNQP8KW~ zH}DbufaA&;f55}yZ0_oo2EWHkeC`jMhjW7iO<`15`thr$CTK6W)P_OOS#C}KOs1lE zMa5_~9se8T3#0M$r&zx5`%iV-SgY(PH>Uno1z*3^XR<*oy79x3LtfQ2k#F-u5O$5O`Lma&`_tYj6dS;Jb^ zv7Qaovyn|~rhzSNWgFYs!A^G3$ZqzqmwjZ}&jAi{h{GJ=D932xI43yCDNb{Svz+5R z7r01{W-f7=7OrrWYqWBm8{DLgJh!;b9qw|E`?T|bhdiRdW1i5#Q=ZXD#B*Nol2=1f mrmOTV%nj#?iIFZ|^M-DEcuOzu=;J*_`uV`ep~T2QU+h2pw(C^@ delta 653 zcmWm8$#Tm90Knn?laN;1*mtpp*tgiX2C=Jsrzjd~ZM2A`w5n2)F*3R06^zNDt}g9( z1}|Wo%yu zGn`38{s!6Ha3t{|l+FGAQ{OhyYCEb;@qcwexspm|f>d8VS;!{?LWGGhiqS-=rH(Pw z(?BCJ#xjoaOkg6Dn9LNWGL7lXU?#JOGn+ZgWghccK!SxVV&rWxOIXS>ma~GDtYS55 zSWAj^tY-ro*~DhHu$66WX9rEB*~u<;lVJ~g*~fkkaF9bBrkNugfMK008Wv+0QR<3cK8?=$-CbwwkHg~woJ?`^>4stxClP(_dm?z|U$}^txVlbcV lE`14qs-z3ip>AICiXM7-O&@RQ=Pd;Wc*py}=uojg^dIs~>>L09 diff --git a/3rdparty/ffmpeg/opencv_ffmpeg_64.dll b/3rdparty/ffmpeg/opencv_ffmpeg_64.dll index 1cfdddec7bb909f33ce5eaee88cad5722af31193..70b353520e6e0dd7dca1a23e566f6a64d30e470d 100644 GIT binary patch delta 631 zcmWm8OH<4N008j$+hrqqctj}g)~k}JNR+p--mmp6gtC=Lr93M(su`x5>ELL_S$oK> zYu})Qrmx^D_&NOUzxmn8@H}4!Lk-jMZ$q(AQ{%|5KQoy@%jl1+zd=`OEc<(U(2*+1 zs|bSbRC9hTEhr!TU62aK`xDV*A{wxO5MdUwhzMycW(nymWf>V{l0`PlS;0zHk;7`% zkjq-uv7S8g*}z6Nv6(GwWg7+jzinp+JK4o<3MrzPJ(RGQQueW*GRmpo00*h$5LF!J z2-VbZlw%y{1SdJgY0gkf9cPJgj`LjLBA2+#6|QoP>)asDO>S|UJKW_S^)zsw2Rx*a zM?B^UO*HeA1TD1E#xvS^&I>wtNhe)&^NJpNdCeQ%P9>u6Cgwu*)A3{^{GJc=(a!)M S`9zXIKJ$g4sYrNu_UAtln%Elv delta 631 zcmWm8NmtAP008j!Z-$Aq+LyA{*hwL>jO@#_Sjt*Ep5^m!=tn9xHWCkI{*L~dp3D#0QsV`Gg0A$J!f!c2N4mVY zDhRsM?IrQ-pd$6VEFFvuB%;YgG$4x*VdgNG2-(bIJ~=EPmpt+*ppYUKvWUejVJXX4 z&I(qtiegGw%^KFSj`eJylrsL`HnNG$Y+)}r*iSVFILILm z6XOUq9OW3tIl)Ozahfxn`Xy+jb9`Tqbbnui;y6EN^&v`))FX^R^SG?v;CJ}x6btd#Z6-!3K@95_}0}S$k SA(9O9kxz_dBH_`gpZ@^uec0Xr From f42b38ac440b7ee576381ee00c3b69c9b8870eb3 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 19 Sep 2012 16:42:39 +0400 Subject: [PATCH 2/2] Refactor fast NL-means denoising * reorder arguments * rewrite accuracy tests * replace doubles with integer arithmetic inside the main loop --- modules/photo/include/opencv2/photo/photo.hpp | 22 +- modules/photo/src/denoising.cpp | 32 ++- .../src/fast_nlmeans_denoising_invoker.hpp | 6 +- .../fast_nlmeans_multi_denoising_invoker.hpp | 6 +- modules/photo/test/test_denoising.cpp | 193 ++++++------------ 5 files changed, 93 insertions(+), 166 deletions(-) diff --git a/modules/photo/include/opencv2/photo/photo.hpp b/modules/photo/include/opencv2/photo/photo.hpp index bae83bbb0e..07b27abc0f 100644 --- a/modules/photo/include/opencv2/photo/photo.hpp +++ b/modules/photo/include/opencv2/photo/photo.hpp @@ -68,26 +68,24 @@ CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, int flags ); -CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, - int templateWindowSize, int searchWindowSize, int h); +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, int h = 3, + int templateWindowSize = 7, int searchWindowSize = 21); CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents); + int h = 3, int hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); -CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, - OutputArray dst, - int templateWindowSize, int searchWindowSize, int h); + int h = 3, int templateWindowSize = 7, int searchWindowSize = 21); -CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, +CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, - OutputArray dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents); + int h = 3, int hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); } -#endif +#endif //__cplusplus #endif diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index d3f1c09aaf..f71c37cf43 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -45,8 +45,8 @@ #include "fast_nlmeans_denoising_invoker.hpp" #include "fast_nlmeans_multi_denoising_invoker.hpp" -void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, - int templateWindowSize, int searchWindowSize, int h) +void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, int h, + int templateWindowSize, int searchWindowSize) { Mat src = _src.getMat(); _dst.create(src.size(), src.type()); @@ -75,8 +75,8 @@ void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, } void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents) + int h, int hForColorComponents, + int templateWindowSize, int searchWindowSize) { Mat src = _src.getMat(); _dst.create(src.size(), src.type()); @@ -96,8 +96,8 @@ void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, int from_to[] = { 0,0, 1,1, 2,2 }; mixChannels(&src_lab, 1, l_ab, 2, from_to, 3); - fastNlMeansDenoising(l, l, templateWindowSize, searchWindowSize, h); - fastNlMeansDenoising(ab, ab, templateWindowSize, searchWindowSize, hForColorComponents); + fastNlMeansDenoising(l, l, h, templateWindowSize, searchWindowSize); + fastNlMeansDenoising(ab, ab, hForColorComponents, templateWindowSize, searchWindowSize); Mat l_ab_denoised[] = { l, ab }; Mat dst_lab(src.size(), src.type()); @@ -138,10 +138,9 @@ static void fastNlMeansDenoisingMultiCheckPreconditions( } } -void cv::fastNlMeansDenoisingMulti( InputArrayOfArrays _srcImgs, +void cv::fastNlMeansDenoisingMulti( InputArrayOfArrays _srcImgs, OutputArray _dst, int imgToDenoiseIndex, int temporalWindowSize, - OutputArray _dst, - int templateWindowSize, int searchWindowSize, int h) + int h, int templateWindowSize, int searchWindowSize) { vector srcImgs; _srcImgs.getMatVector(srcImgs); @@ -178,11 +177,10 @@ void cv::fastNlMeansDenoisingMulti( InputArrayOfArrays _srcImgs, } } -void cv::fastNlMeansDenoisingColoredMulti( InputArrayOfArrays _srcImgs, +void cv::fastNlMeansDenoisingColoredMulti( InputArrayOfArrays _srcImgs, OutputArray _dst, int imgToDenoiseIndex, int temporalWindowSize, - OutputArray _dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents) + int h, int hForColorComponents, + int templateWindowSize, int searchWindowSize) { vector srcImgs; _srcImgs.getMatVector(srcImgs); @@ -222,12 +220,12 @@ void cv::fastNlMeansDenoisingColoredMulti( InputArrayOfArrays _srcImgs, Mat dst_ab; fastNlMeansDenoisingMulti( - l, imgToDenoiseIndex, temporalWindowSize, - dst_l, templateWindowSize, searchWindowSize, h); + l, dst_l, imgToDenoiseIndex, temporalWindowSize, + h, templateWindowSize, searchWindowSize); fastNlMeansDenoisingMulti( - ab, imgToDenoiseIndex, temporalWindowSize, - dst_ab, templateWindowSize, searchWindowSize, hForColorComponents); + ab, dst_ab, imgToDenoiseIndex, temporalWindowSize, + hForColorComponents, templateWindowSize, searchWindowSize); Mat l_ab_denoised[] = { dst_l, dst_ab }; Mat dst_lab(srcImgs[0].size(), srcImgs[0].type()); diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp index 07159bba47..5f7d1fe59b 100644 --- a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp @@ -257,10 +257,8 @@ void FastNlMeansDenoisingInvoker::operator() (const BlockedRange& range) cons } if (weights_sum > 0) { - for (int channel_num = 0; channel_num < src_.channels(); channel_num++) { - estimation[channel_num] = - cvRound(((double)estimation[channel_num]) / weights_sum); - } + for (int channel_num = 0; channel_num < src_.channels(); channel_num++) + estimation[channel_num] = (estimation[channel_num] + weights_sum/2) / weights_sum; dst_.at(i,j) = saturateCastFromArray(estimation); diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp index b9b8e7f0f7..4151f320ba 100644 --- a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -290,10 +290,8 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) } if (weights_sum > 0) { - for (int channel_num = 0; channel_num < channels_count_; channel_num++) { - estimation[channel_num] = - cvRound(((double)estimation[channel_num]) / weights_sum); - } + for (int channel_num = 0; channel_num < channels_count_; channel_num++) + estimation[channel_num] = (estimation[channel_num] + weights_sum / 2) / weights_sum; dst_.at(i,j) = saturateCastFromArray(estimation); diff --git a/modules/photo/test/test_denoising.cpp b/modules/photo/test/test_denoising.cpp index 6b202f133a..d52d8b40f2 100644 --- a/modules/photo/test/test_denoising.cpp +++ b/modules/photo/test/test_denoising.cpp @@ -47,167 +47,102 @@ using namespace cv; using namespace std; -class CV_DenoisingGrayscaleTest : public cvtest::BaseTest +//#define DUMP_RESULTS + +#ifdef DUMP_RESULTS +# define DUMP(image, path) imwrite(path, image) +#else +# define FUMP(image, path) +#endif + + +TEST(Imgproc_DenoisingGrayscale, regression) { -public: - CV_DenoisingGrayscaleTest(); - ~CV_DenoisingGrayscaleTest(); -protected: - void run(int); -}; + string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; + string original_path = folder + "lena_noised_gaussian_sigma=10.png"; + string expected_path = folder + "lena_noised_denoised_grayscale_tw=7_sw=21_h=10.png"; -CV_DenoisingGrayscaleTest::CV_DenoisingGrayscaleTest() {} -CV_DenoisingGrayscaleTest::~CV_DenoisingGrayscaleTest() {} + Mat original = imread(original_path, CV_LOAD_IMAGE_GRAYSCALE); + Mat expected = imread(expected_path, CV_LOAD_IMAGE_GRAYSCALE); -void CV_DenoisingGrayscaleTest::run( int ) -{ - string folder = string(ts->get_data_path()) + "denoising/"; - Mat orig = imread(folder + "lena_noised_gaussian_sigma=10.png", 0); - Mat exp = imread(folder + "lena_noised_denoised_grayscale_tw=7_sw=21_h=10.png", 0); + ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path; + ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; - if (orig.empty() || exp.empty()) - { - ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); - return; - } + Mat result; + fastNlMeansDenoising(original, result, 10); - Mat res; - fastNlMeansDenoising(orig, res, 7, 21, 10); + DUMP(result, expected_path + ".res.png"); - if (norm(res - exp) > 0) { - ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); - } else { - ts->set_failed_test_info(cvtest::TS::OK); - } + ASSERT_EQ(0, norm(result != expected)); } -class CV_DenoisingColoredTest : public cvtest::BaseTest +TEST(Imgproc_DenoisingColored, regression) { -public: - CV_DenoisingColoredTest(); - ~CV_DenoisingColoredTest(); -protected: - void run(int); -}; + string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; + string original_path = folder + "lena_noised_gaussian_sigma=10.png"; + string expected_path = folder + "lena_noised_denoised_lab12_tw=7_sw=21_h=10_h2=10.png"; -CV_DenoisingColoredTest::CV_DenoisingColoredTest() {} -CV_DenoisingColoredTest::~CV_DenoisingColoredTest() {} + Mat original = imread(original_path, CV_LOAD_IMAGE_COLOR); + Mat expected = imread(expected_path, CV_LOAD_IMAGE_COLOR); -void CV_DenoisingColoredTest::run( int ) -{ - string folder = string(ts->get_data_path()) + "denoising/"; - Mat orig = imread(folder + "lena_noised_gaussian_sigma=10.png", 1); - Mat exp = imread(folder + "lena_noised_denoised_lab12_tw=7_sw=21_h=10_h2=10.png", 1); + ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path; + ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; - if (orig.empty() || exp.empty()) - { - ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); - return; - } + Mat result; + fastNlMeansDenoisingColored(original, result, 10, 10); - Mat res; - fastNlMeansDenoisingColored(orig, res, 7, 21, 10, 10); + DUMP(result, expected_path + ".res.png"); - if (norm(res - exp) > 0) { - ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); - } else { - ts->set_failed_test_info(cvtest::TS::OK); - } + ASSERT_EQ(0, norm(result != expected)); } -class CV_DenoisingGrayscaleMultiTest : public cvtest::BaseTest +TEST(Imgproc_DenoisingGrayscaleMulti, regression) { -public: - CV_DenoisingGrayscaleMultiTest(); - ~CV_DenoisingGrayscaleMultiTest(); -protected: - void run(int); -}; - -CV_DenoisingGrayscaleMultiTest::CV_DenoisingGrayscaleMultiTest() {} -CV_DenoisingGrayscaleMultiTest::~CV_DenoisingGrayscaleMultiTest() {} - -void CV_DenoisingGrayscaleMultiTest::run( int ) -{ - string folder = string(ts->get_data_path()) + "denoising/"; - const int imgs_count = 3; - vector src_imgs(imgs_count); - src_imgs[0] = imread(folder + "lena_noised_gaussian_sigma=20_multi_0.png", 0); - src_imgs[1] = imread(folder + "lena_noised_gaussian_sigma=20_multi_1.png", 0); - src_imgs[2] = imread(folder + "lena_noised_gaussian_sigma=20_multi_2.png", 0); - - Mat exp = imread(folder + "lena_noised_denoised_multi_tw=7_sw=21_h=15.png", 0); + string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; - bool have_empty_src = false; - for (int i = 0; i < imgs_count; i++) { - have_empty_src |= src_imgs[i].empty(); - } + string expected_path = folder + "lena_noised_denoised_multi_tw=7_sw=21_h=15.png"; + Mat expected = imread(expected_path, CV_LOAD_IMAGE_GRAYSCALE); + ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; - if (have_empty_src || exp.empty()) + vector original(imgs_count); + for (int i = 0; i < imgs_count; i++) { - ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); - return; + string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i); + original[i] = imread(original_path, CV_LOAD_IMAGE_GRAYSCALE); + ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path; } - Mat res; - fastNlMeansDenoisingMulti(src_imgs, imgs_count / 2, imgs_count, res, 7, 21, 15); + Mat result; + fastNlMeansDenoisingMulti(original, result, imgs_count / 2, imgs_count, 15); - if (norm(res - exp) > 0) { - ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); - } else { - ts->set_failed_test_info(cvtest::TS::OK); - } + DUMP(result, expected_path + ".res.png"); + + ASSERT_EQ(0, norm(result != expected)); } -class CV_DenoisingColoredMultiTest : public cvtest::BaseTest +TEST(Imgproc_DenoisingColoredMulti, regression) { -public: - CV_DenoisingColoredMultiTest(); - ~CV_DenoisingColoredMultiTest(); -protected: - void run(int); -}; - -CV_DenoisingColoredMultiTest::CV_DenoisingColoredMultiTest() {} -CV_DenoisingColoredMultiTest::~CV_DenoisingColoredMultiTest() {} - -void CV_DenoisingColoredMultiTest::run( int ) -{ - string folder = string(ts->get_data_path()) + "denoising/"; - const int imgs_count = 3; - vector src_imgs(imgs_count); - src_imgs[0] = imread(folder + "lena_noised_gaussian_sigma=20_multi_0.png", 1); - src_imgs[1] = imread(folder + "lena_noised_gaussian_sigma=20_multi_1.png", 1); - src_imgs[2] = imread(folder + "lena_noised_gaussian_sigma=20_multi_2.png", 1); - - Mat exp = imread(folder + "lena_noised_denoised_multi_lab12_tw=7_sw=21_h=10_h2=15.png", 1); - - bool have_empty_src = false; - for (int i = 0; i < imgs_count; i++) { - have_empty_src |= src_imgs[i].empty(); - } + string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; - if (have_empty_src || exp.empty()) + string expected_path = folder + "lena_noised_denoised_multi_lab12_tw=7_sw=21_h=10_h2=15.png"; + Mat expected = imread(expected_path, CV_LOAD_IMAGE_COLOR); + ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; + + vector original(imgs_count); + for (int i = 0; i < imgs_count; i++) { - ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); - return; + string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i); + original[i] = imread(original_path, CV_LOAD_IMAGE_COLOR); + ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path; } - Mat res; - fastNlMeansDenoisingColoredMulti(src_imgs, imgs_count / 2, imgs_count, res, 7, 21, 10, 15); + Mat result; + fastNlMeansDenoisingColoredMulti(original, result, imgs_count / 2, imgs_count, 10, 15); - if (norm(res - exp) > 0) { - ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); - } else { - ts->set_failed_test_info(cvtest::TS::OK); - } + DUMP(result, expected_path + ".res.png"); + + ASSERT_EQ(0, norm(result != expected)); } - -TEST(Imgproc_DenoisingGrayscale, regression) { CV_DenoisingGrayscaleTest test; test.safe_run(); } -TEST(Imgproc_DenoisingColored, regression) { CV_DenoisingColoredTest test; test.safe_run(); } -TEST(Imgproc_DenoisingGrayscaleMulti, regression) { CV_DenoisingGrayscaleMultiTest test; test.safe_run(); } -TEST(Imgproc_DenoisingColoredMulti, regression) { CV_DenoisingColoredMultiTest test; test.safe_run(); } -