mirror of https://github.com/opencv/opencv.git
At this point we have a skeleton of a new module (optim) which can barely compile properly (unlike previous commit). Besides, there is a first draft of solver and lpsolver (linear optimization solver) in this commit.pull/1192/head
parent
f2afe64521
commit
f41b8b90ff
18 changed files with 80 additions and 592 deletions
@ -1,2 +1,3 @@ |
||||
set(the_description "Generic optimization") |
||||
ocv_define_module(optim) |
||||
ocv_define_module(optim opencv_imgproc) |
||||
#ocv_define_module(optim core) |
||||
|
@ -1,91 +0,0 @@ |
||||
Denoising |
||||
========== |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
fastNlMeansDenoising |
||||
-------------------- |
||||
Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ |
||||
with several computational optimizations. Noise expected to be a gaussian white noise |
||||
|
||||
.. ocv:function:: void fastNlMeansDenoising( InputArray src, OutputArray dst, float h=3, int templateWindowSize=7, int searchWindowSize=21 ) |
||||
|
||||
:param src: Input 8-bit 1-channel, 2-channel or 3-channel image. |
||||
|
||||
:param dst: Output image with the same size and type as ``src`` . |
||||
|
||||
:param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels |
||||
|
||||
:param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels |
||||
|
||||
:param h: Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise |
||||
|
||||
This function expected to be applied to grayscale images. For colored images look at ``fastNlMeansDenoisingColored``. |
||||
Advanced usage of this functions can be manual denoising of colored image in different colorspaces. |
||||
Such approach is used in ``fastNlMeansDenoisingColored`` by converting image to CIELAB colorspace and then separately denoise L and AB components with different h parameter. |
||||
|
||||
fastNlMeansDenoisingColored |
||||
--------------------------- |
||||
Modification of ``fastNlMeansDenoising`` function for colored images |
||||
|
||||
.. ocv:function:: void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, float h=3, float hColor=3, int templateWindowSize=7, int searchWindowSize=21 ) |
||||
|
||||
:param src: Input 8-bit 3-channel image. |
||||
|
||||
:param dst: Output image with the same size and type as ``src`` . |
||||
|
||||
:param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels |
||||
|
||||
:param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels |
||||
|
||||
:param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise |
||||
|
||||
:param hForColorComponents: The same as h but for color components. For most images value equals 10 will be enought to remove colored noise and do not distort colors |
||||
|
||||
The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoising`` function. |
||||
|
||||
fastNlMeansDenoisingMulti |
||||
------------------------- |
||||
Modification of ``fastNlMeansDenoising`` function for images sequence where consequtive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. |
||||
For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394 |
||||
|
||||
.. ocv:function:: void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, float h=3, int templateWindowSize=7, int searchWindowSize=21 ) |
||||
|
||||
:param srcImgs: Input 8-bit 1-channel, 2-channel or 3-channel images sequence. All images should have the same type and size. |
||||
|
||||
:param imgToDenoiseIndex: Target image to denoise index in ``srcImgs`` sequence |
||||
|
||||
:param temporalWindowSize: Number of surrounding images to use for target image denoising. Should be odd. Images from ``imgToDenoiseIndex - temporalWindowSize / 2`` to ``imgToDenoiseIndex - temporalWindowSize / 2`` from ``srcImgs`` will be used to denoise ``srcImgs[imgToDenoiseIndex]`` image. |
||||
|
||||
:param dst: Output image with the same size and type as ``srcImgs`` images. |
||||
|
||||
:param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels |
||||
|
||||
:param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels |
||||
|
||||
:param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise |
||||
|
||||
fastNlMeansDenoisingColoredMulti |
||||
-------------------------------- |
||||
Modification of ``fastNlMeansDenoisingMulti`` function for colored images sequences |
||||
|
||||
.. ocv:function:: void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, float h=3, float hColor=3, int templateWindowSize=7, int searchWindowSize=21 ) |
||||
|
||||
:param srcImgs: Input 8-bit 3-channel images sequence. All images should have the same type and size. |
||||
|
||||
:param imgToDenoiseIndex: Target image to denoise index in ``srcImgs`` sequence |
||||
|
||||
:param temporalWindowSize: Number of surrounding images to use for target image denoising. Should be odd. Images from ``imgToDenoiseIndex - temporalWindowSize / 2`` to ``imgToDenoiseIndex - temporalWindowSize / 2`` from ``srcImgs`` will be used to denoise ``srcImgs[imgToDenoiseIndex]`` image. |
||||
|
||||
:param dst: Output image with the same size and type as ``srcImgs`` images. |
||||
|
||||
:param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels |
||||
|
||||
:param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels |
||||
|
||||
:param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise. |
||||
|
||||
:param hForColorComponents: The same as h but for color components. |
||||
|
||||
The function converts images to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoisingMulti`` function. |
||||
|
@ -1,32 +0,0 @@ |
||||
Inpainting |
||||
========== |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
inpaint |
||||
----------- |
||||
Restores the selected region in an image using the region neighborhood. |
||||
|
||||
.. ocv:function:: void inpaint( InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, int flags ) |
||||
|
||||
.. ocv:pyfunction:: cv2.inpaint(src, inpaintMask, inpaintRadius, flags[, dst]) -> dst |
||||
|
||||
.. ocv:cfunction:: void cvInpaint( const CvArr* src, const CvArr* inpaint_mask, CvArr* dst, double inpaintRange, int flags ) |
||||
|
||||
:param src: Input 8-bit 1-channel or 3-channel image. |
||||
|
||||
:param inpaintMask: Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that needs to be inpainted. |
||||
|
||||
:param dst: Output image with the same size and type as ``src`` . |
||||
|
||||
:param inpaintRadius: Radius of a circular neighborhood of each point inpainted that is considered by the algorithm. |
||||
|
||||
:param flags: Inpainting method that could be one of the following: |
||||
|
||||
* **INPAINT_NS** Navier-Stokes based method. |
||||
|
||||
* **INPAINT_TELEA** Method by Alexandru Telea [Telea04]_. |
||||
|
||||
The function reconstructs the selected image area from the pixel near the area boundary. The function may be used to remove dust and scratches from a scanned photo, or to remove undesirable objects from still images or video. See |
||||
http://en.wikipedia.org/wiki/Inpainting |
||||
for more details. |
@ -1,11 +0,0 @@ |
||||
******************************** |
||||
photo. Computational Photography |
||||
******************************** |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
.. toctree:: |
||||
:maxdepth: 2 |
||||
|
||||
inpainting |
||||
denoising |
@ -1,38 +0,0 @@ |
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
CV_ENUM(InpaintingMethod, INPAINT_NS, INPAINT_TELEA) |
||||
typedef std::tr1::tuple<Size, InpaintingMethod> InpaintArea_InpaintingMethod_t; |
||||
typedef perf::TestBaseWithParam<InpaintArea_InpaintingMethod_t> InpaintArea_InpaintingMethod; |
||||
|
||||
|
||||
PERF_TEST_P(InpaintArea_InpaintingMethod, inpaint, |
||||
testing::Combine( |
||||
testing::Values(::perf::szSmall24, ::perf::szSmall32, ::perf::szSmall64), |
||||
InpaintingMethod::all() |
||||
) |
||||
) |
||||
{ |
||||
Mat src = imread(getDataPath("gpu/hog/road.png")); |
||||
|
||||
Size sz = get<0>(GetParam()); |
||||
int inpaintingMethod = get<1>(GetParam()); |
||||
|
||||
Mat mask(src.size(), CV_8UC1, Scalar(0)); |
||||
Mat result(src.size(), src.type()); |
||||
|
||||
Rect inpaintArea(src.cols/3, src.rows/3, sz.width, sz.height); |
||||
mask(inpaintArea).setTo(255); |
||||
|
||||
declare.in(src, mask).out(result).time(120); |
||||
|
||||
TEST_CYCLE() inpaint(src, mask, result, 10.0, inpaintingMethod); |
||||
|
||||
Mat inpaintedArea = result(inpaintArea); |
||||
SANITY_CHECK(inpaintedArea); |
||||
} |
@ -1,3 +0,0 @@ |
||||
#include "perf_precomp.hpp" |
||||
|
||||
CV_PERF_TEST_MAIN(photo) |
@ -1 +0,0 @@ |
||||
#include "perf_precomp.hpp" |
@ -1,20 +0,0 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__ |
||||
#define __OPENCV_PERF_PRECOMP_HPP__ |
||||
|
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/photo.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY |
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined |
||||
#endif |
||||
|
||||
#endif |
@ -1,45 +1,2 @@ |
||||
#include "opencv2/opencv.hpp" |
||||
|
||||
namespace cv { |
||||
namespace optim { |
||||
|
||||
class Solver : public Algorithm /* Algorithm is base OpenCV class */ |
||||
{ |
||||
class Function |
||||
{ |
||||
public: |
||||
virtual ~Function() {} |
||||
virtual double calc(InputArray args) const = 0; |
||||
virtual double calc(InputArgs, OutputArray grad) const = 0; |
||||
}; |
||||
|
||||
// could be reused for all the generic algorithms like downhill simplex.
|
||||
virtual void solve(InputArray x0, OutputArray result) const = 0; |
||||
|
||||
virtual void setTermCriteria(const TermCriteria& criteria) = 0; |
||||
virtual TermCriteria getTermCriteria() = 0; |
||||
|
||||
// more detailed API to be defined later ...
|
||||
}; |
||||
|
||||
class LPSolver : public Solver |
||||
{ |
||||
public: |
||||
virtual void solve(InputArray coeffs, InputArray constraints, OutputArray result) const = 0; |
||||
// ...
|
||||
}; |
||||
|
||||
Ptr<LPSolver> createLPSimplexSolver(); |
||||
|
||||
}} |
||||
|
||||
/*===============
|
||||
Hill climbing solver is more generic one:*/ |
||||
/*
|
||||
class DownhillSolver : public Solver |
||||
{ |
||||
public: |
||||
// various setters and getters, if needed
|
||||
}; |
||||
|
||||
Ptr<DownhillSolver> createDownhillSolver(const Ptr<Solver::Function>& func);*/ |
||||
#include "precomp.hpp" |
||||
#include "opencv2/optim.hpp" |
||||
|
@ -0,0 +1,44 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
/* End of file. */ |
@ -1,158 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include "opencv2/photo.hpp" |
||||
#include <string> |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
//#define DUMP_RESULTS
|
||||
|
||||
#ifdef DUMP_RESULTS |
||||
# define DUMP(image, path) imwrite(path, image) |
||||
#else |
||||
# define DUMP(image, path) |
||||
#endif |
||||
|
||||
|
||||
TEST(Photo_DenoisingGrayscale, regression) |
||||
{ |
||||
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"; |
||||
|
||||
Mat original = imread(original_path, IMREAD_GRAYSCALE); |
||||
Mat expected = imread(expected_path, IMREAD_GRAYSCALE); |
||||
|
||||
ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path; |
||||
ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; |
||||
|
||||
Mat result; |
||||
fastNlMeansDenoising(original, result, 10); |
||||
|
||||
DUMP(result, expected_path + ".res.png"); |
||||
|
||||
ASSERT_EQ(0, norm(result != expected)); |
||||
} |
||||
|
||||
TEST(Photo_DenoisingColored, regression) |
||||
{ |
||||
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"; |
||||
|
||||
Mat original = imread(original_path, IMREAD_COLOR); |
||||
Mat expected = imread(expected_path, IMREAD_COLOR); |
||||
|
||||
ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path; |
||||
ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; |
||||
|
||||
Mat result; |
||||
fastNlMeansDenoisingColored(original, result, 10, 10); |
||||
|
||||
DUMP(result, expected_path + ".res.png"); |
||||
|
||||
ASSERT_EQ(0, norm(result != expected)); |
||||
} |
||||
|
||||
TEST(Photo_DenoisingGrayscaleMulti, regression) |
||||
{ |
||||
const int imgs_count = 3; |
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; |
||||
|
||||
string expected_path = folder + "lena_noised_denoised_multi_tw=7_sw=21_h=15.png"; |
||||
Mat expected = imread(expected_path, IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; |
||||
|
||||
vector<Mat> original(imgs_count); |
||||
for (int i = 0; i < imgs_count; i++) |
||||
{ |
||||
string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i); |
||||
original[i] = imread(original_path, IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path; |
||||
} |
||||
|
||||
Mat result; |
||||
fastNlMeansDenoisingMulti(original, result, imgs_count / 2, imgs_count, 15); |
||||
|
||||
DUMP(result, expected_path + ".res.png"); |
||||
|
||||
ASSERT_EQ(0, norm(result != expected)); |
||||
} |
||||
|
||||
TEST(Photo_DenoisingColoredMulti, regression) |
||||
{ |
||||
const int imgs_count = 3; |
||||
string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/"; |
||||
|
||||
string expected_path = folder + "lena_noised_denoised_multi_lab12_tw=7_sw=21_h=10_h2=15.png"; |
||||
Mat expected = imread(expected_path, IMREAD_COLOR); |
||||
ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path; |
||||
|
||||
vector<Mat> original(imgs_count); |
||||
for (int i = 0; i < imgs_count; i++) |
||||
{ |
||||
string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i); |
||||
original[i] = imread(original_path, IMREAD_COLOR); |
||||
ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path; |
||||
} |
||||
|
||||
Mat result; |
||||
fastNlMeansDenoisingColoredMulti(original, result, imgs_count / 2, imgs_count, 10, 15); |
||||
|
||||
DUMP(result, expected_path + ".res.png"); |
||||
|
||||
ASSERT_EQ(0, norm(result != expected)); |
||||
} |
||||
|
||||
TEST(Photo_White, issue_2646) |
||||
{ |
||||
cv::Mat img(50, 50, CV_8UC1, cv::Scalar::all(255)); |
||||
cv::Mat filtered; |
||||
cv::fastNlMeansDenoising(img, filtered); |
||||
|
||||
int nonWhitePixelsCount = (int)img.total() - cv::countNonZero(filtered == img); |
||||
|
||||
ASSERT_EQ(0, nonWhitePixelsCount); |
||||
} |
@ -1,119 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include <string> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
|
||||
class CV_InpaintTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_InpaintTest(); |
||||
~CV_InpaintTest(); |
||||
protected: |
||||
void run(int); |
||||
}; |
||||
|
||||
CV_InpaintTest::CV_InpaintTest() |
||||
{ |
||||
} |
||||
CV_InpaintTest::~CV_InpaintTest() {} |
||||
|
||||
void CV_InpaintTest::run( int ) |
||||
{ |
||||
string folder = string(ts->get_data_path()) + "inpaint/"; |
||||
Mat orig = imread(folder + "orig.png"); |
||||
Mat exp1 = imread(folder + "exp1.png"); |
||||
Mat exp2 = imread(folder + "exp2.png"); |
||||
Mat mask = imread(folder + "mask.png"); |
||||
|
||||
if (orig.empty() || exp1.empty() || exp2.empty() || mask.empty()) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
Mat inv_mask; |
||||
mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0); |
||||
|
||||
Mat mask1ch; |
||||
cv::cvtColor(mask, mask1ch, COLOR_BGR2GRAY); |
||||
|
||||
Mat test = orig.clone(); |
||||
test.setTo(Scalar::all(255), mask1ch); |
||||
|
||||
Mat res1, res2; |
||||
inpaint( test, mask1ch, res1, 5, INPAINT_NS ); |
||||
inpaint( test, mask1ch, res2, 5, INPAINT_TELEA ); |
||||
|
||||
Mat diff1, diff2; |
||||
absdiff( orig, res1, diff1 ); |
||||
absdiff( orig, res2, diff2 ); |
||||
|
||||
double n1 = norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1)); |
||||
double n2 = norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1)); |
||||
|
||||
if (n1 != 0 || n2 != 0) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
return; |
||||
} |
||||
|
||||
absdiff( exp1, res1, diff1 ); |
||||
absdiff( exp2, res2, diff2 ); |
||||
|
||||
n1 = norm(diff1.reshape(1), NORM_INF, mask.reshape(1)); |
||||
n2 = norm(diff2.reshape(1), NORM_INF, mask.reshape(1)); |
||||
|
||||
const int jpeg_thres = 3; |
||||
if (n1 > jpeg_thres || n2 > jpeg_thres) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
return; |
||||
} |
||||
|
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
} |
||||
|
||||
TEST(Photo_Inpaint, regression) { CV_InpaintTest test; test.safe_run(); } |
@ -1,3 +0,0 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
CV_TEST_MAIN("cv") |
@ -1 +0,0 @@ |
||||
#include "test_precomp.hpp" |
@ -1,17 +0,0 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__ |
||||
#define __OPENCV_TEST_PRECOMP_HPP__ |
||||
|
||||
#include <iostream> |
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/photo.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
#endif |
Loading…
Reference in new issue