Path: blob/master/modules/photo/test/test_inpaint.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "test_precomp.hpp"4344namespace opencv_test { namespace {4546class CV_InpaintTest : public cvtest::BaseTest47{48public:49CV_InpaintTest();50~CV_InpaintTest();51protected:52void run(int);53};5455CV_InpaintTest::CV_InpaintTest()56{57}58CV_InpaintTest::~CV_InpaintTest() {}5960void CV_InpaintTest::run( int )61{62string folder = string(ts->get_data_path()) + "inpaint/";63Mat orig = imread(folder + "orig.png");64Mat exp1 = imread(folder + "exp1.png");65Mat exp2 = imread(folder + "exp2.png");66Mat mask = imread(folder + "mask.png");6768if (orig.empty() || exp1.empty() || exp2.empty() || mask.empty())69{70ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );71return;72}7374Mat inv_mask;75mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0);7677Mat mask1ch;78cv::cvtColor(mask, mask1ch, COLOR_BGR2GRAY);7980Mat test = orig.clone();81test.setTo(Scalar::all(255), mask1ch);8283Mat res1, res2;84inpaint( test, mask1ch, res1, 5, INPAINT_NS );85inpaint( test, mask1ch, res2, 5, INPAINT_TELEA );8687Mat diff1, diff2;88absdiff( orig, res1, diff1 );89absdiff( orig, res2, diff2 );9091double n1 = cvtest::norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));92double n2 = cvtest::norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));9394if (n1 != 0 || n2 != 0)95{96ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );97return;98}99100absdiff( exp1, res1, diff1 );101absdiff( exp2, res2, diff2 );102103n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask.reshape(1));104n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask.reshape(1));105106const int jpeg_thres = 3;107if (n1 > jpeg_thres || n2 > jpeg_thres)108{109ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );110return;111}112113ts->set_failed_test_info(cvtest::TS::OK);114}115116TEST(Photo_Inpaint, regression) { CV_InpaintTest test; test.safe_run(); }117118typedef testing::TestWithParam<tuple<int> > formats;119120TEST_P(formats, 1c)121{122const int type = get<0>(GetParam());123Mat src(100, 100, type);124src.setTo(Scalar::all(128));125Mat ref = src.clone();126Mat dst, mask = Mat::zeros(src.size(), CV_8U);127128circle(src, Point(50, 50), 5, Scalar(200), 6);129circle(mask, Point(50, 50), 5, Scalar(200), 6);130inpaint(src, mask, dst, 10, INPAINT_NS);131132Mat dst2;133inpaint(src, mask, dst2, 10, INPAINT_TELEA);134135ASSERT_LE(cv::norm(dst, ref, NORM_INF), 3.);136ASSERT_LE(cv::norm(dst2, ref, NORM_INF), 3.);137}138139INSTANTIATE_TEST_CASE_P(Photo_Inpaint, formats, testing::Values(CV_32F, CV_16U, CV_8U));140141}} // namespace142143144