Commit 0fef7f8b authored by Andrey Pavlenko's avatar Andrey Pavlenko Committed by OpenCV Buildbot

Merge pull request #2217 from ilya-lavrenov:tapi_superres

parents 13875b5f 6ad4823f
......@@ -217,7 +217,7 @@ public:
virtual void createSameSize(const _InputArray& arr, int mtype) const;
virtual void release() const;
virtual void clear() const;
virtual void setTo(const _InputArray& value) const;
virtual void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
};
......
......@@ -5,6 +5,8 @@
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//#define CV_OPENCL_RUN_VERBOSE
#ifdef HAVE_OPENCL
#ifdef CV_OPENCL_RUN_VERBOSE
......
......@@ -2560,7 +2560,7 @@ cuda::CudaMem& _OutputArray::getCudaMemRef() const
return *(cuda::CudaMem*)obj;
}
void _OutputArray::setTo(const _InputArray& arr) const
void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const
{
int k = kind();
......@@ -2569,10 +2569,16 @@ void _OutputArray::setTo(const _InputArray& arr) const
else if( k == MAT || k == MATX || k == STD_VECTOR )
{
Mat m = getMat();
m.setTo(arr);
m.setTo(arr, mask);
}
else if( k == UMAT )
((UMat*)obj)->setTo(arr);
((UMat*)obj)->setTo(arr, mask);
else if( k == GPU_MAT )
{
Mat value = arr.getMat();
CV_Assert( checkScalar(value, type(), arr.kind(), _InputArray::GPU_MAT) );
((cuda::GpuMat*)obj)->setTo(Scalar(Vec<double, 4>((double *)value.data)), mask);
}
else
CV_Error(Error::StsNotImplemented, "");
}
......
......@@ -5,5 +5,4 @@ endif()
set(the_description "Super Resolution")
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 -Wundef)
ocv_define_module(superres opencv_imgproc opencv_video
OPTIONAL opencv_highgui opencv_ocl
opencv_cudaarithm opencv_cudafilters opencv_cudawarping opencv_cudaimgproc opencv_cudaoptflow opencv_cudacodec)
OPTIONAL opencv_highgui opencv_cudaarithm opencv_cudafilters opencv_cudawarping opencv_cudaimgproc opencv_cudaoptflow opencv_cudacodec)
......@@ -83,6 +83,8 @@ namespace cv
virtual void initImpl(Ptr<FrameSource>& frameSource) = 0;
virtual void processImpl(Ptr<FrameSource>& frameSource, OutputArray output) = 0;
bool isUmat_;
private:
Ptr<FrameSource> frameSource_;
bool firstCall_;
......
......@@ -41,6 +41,7 @@
//M*/
#include "perf_precomp.hpp"
#include "opencv2/ts/ocl_perf.hpp"
using namespace std;
using namespace std::tr1;
......@@ -91,37 +92,26 @@ namespace
class ZeroOpticalFlow : public DenseOpticalFlowExt
{
public:
void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
virtual void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
{
cv::Size size = frame0.size();
if (!flow2.needed())
{
flow1.create(size, CV_32FC2);
if (flow1.kind() == cv::_InputArray::GPU_MAT)
flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
else
flow1.getMatRef().setTo(cv::Scalar::all(0));
flow1.setTo(cv::Scalar::all(0));
}
else
{
flow1.create(size, CV_32FC1);
flow2.create(size, CV_32FC1);
if (flow1.kind() == cv::_InputArray::GPU_MAT)
flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
else
flow1.getMatRef().setTo(cv::Scalar::all(0));
if (flow2.kind() == cv::_InputArray::GPU_MAT)
flow2.getGpuMatRef().setTo(cv::Scalar::all(0));
else
flow2.getMatRef().setTo(cv::Scalar::all(0));
flow1.setTo(cv::Scalar::all(0));
flow2.setTo(cv::Scalar::all(0));
}
}
void collectGarbage()
virtual void collectGarbage()
{
}
};
......@@ -181,3 +171,48 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
CPU_SANITY_CHECK(dst);
}
}
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
typedef Size_MatType SuperResolution_BTVL1;
OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,
Combine(Values(szSmall64, szSmall128),
Values(MatType(CV_8UC1), MatType(CV_8UC3))))
{
Size_MatType_t params = GetParam();
const Size size = get<0>(params);
const int type = get<1>(params);
Mat frame(size, type);
UMat dst(1, 1, 0);
declare.in(frame, WARMUP_RNG);
const int scale = 2;
const int iterations = 50;
const int temporalAreaRadius = 1;
Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
superRes->set("scale", scale);
superRes->set("iterations", iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius);
superRes->set("opticalFlow", opticalFlow);
superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
// skip first frame
superRes->nextFrame(dst);
OCL_TEST_CYCLE_N(10) superRes->nextFrame(dst);
SANITY_CHECK_NOTHING();
}
} } // namespace cvtest::ocl
#endif // HAVE_OPENCL
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, 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 "perf_precomp.hpp"
#ifdef HAVE_OPENCV_OCL
#include "opencv2/ocl.hpp"
using namespace std;
using namespace testing;
using namespace perf;
using namespace cv;
using namespace cv::superres;
namespace
{
class OneFrameSource_OCL : public FrameSource
{
public:
explicit OneFrameSource_OCL(const ocl::oclMat& frame) : frame_(frame) {}
void nextFrame(OutputArray frame)
{
ocl::getOclMatRef(frame) = frame_;
}
void reset()
{
}
private:
ocl::oclMat frame_;
};
class ZeroOpticalFlowOCL : public DenseOpticalFlowExt
{
public:
void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
{
ocl::oclMat& frame0_ = ocl::getOclMatRef(frame0);
ocl::oclMat& flow1_ = ocl::getOclMatRef(flow1);
ocl::oclMat& flow2_ = ocl::getOclMatRef(flow2);
cv::Size size = frame0_.size();
if(!flow2.needed())
{
flow1_.create(size, CV_32FC2);
flow1_.setTo(Scalar::all(0));
}
else
{
flow1_.create(size, CV_32FC1);
flow2_.create(size, CV_32FC1);
flow1_.setTo(Scalar::all(0));
flow2_.setTo(Scalar::all(0));
}
}
void collectGarbage()
{
}
};
}
PERF_TEST_P(Size_MatType, SuperResolution_BTVL1_OCL,
Combine(Values(szSmall64, szSmall128),
Values(MatType(CV_8UC1), MatType(CV_8UC3))))
{
declare.time(5 * 60);
const Size size = std::tr1::get<0>(GetParam());
const int type = std::tr1::get<1>(GetParam());
Mat frame(size, type);
declare.in(frame, WARMUP_RNG);
ocl::oclMat frame_ocl;
frame_ocl.upload(frame);
const int scale = 2;
const int iterations = 50;
const int temporalAreaRadius = 1;
Ptr<DenseOpticalFlowExt> opticalFlowOcl(new ZeroOpticalFlowOCL);
Ptr<SuperResolution> superRes_ocl = createSuperResolution_BTVL1_OCL();
superRes_ocl->set("scale", scale);
superRes_ocl->set("iterations", iterations);
superRes_ocl->set("temporalAreaRadius", temporalAreaRadius);
superRes_ocl->set("opticalFlow", opticalFlowOcl);
superRes_ocl->setInput(makePtr<OneFrameSource_OCL>(frame_ocl));
ocl::oclMat dst_ocl;
superRes_ocl->nextFrame(dst_ocl);
TEST_CYCLE_N(10) superRes_ocl->nextFrame(dst_ocl);
frame_ocl.release();
CPU_SANITY_CHECK(dst_ocl);
}
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -115,25 +115,18 @@ namespace
void CaptureFrameSource::nextFrame(OutputArray _frame)
{
if (_frame.kind() == _InputArray::MAT)
{
vc_ >> _frame.getMatRef();
}
else if(_frame.kind() == _InputArray::GPU_MAT)
{
vc_ >> frame_;
arrCopy(frame_, _frame);
}
else if(_frame.kind() == _InputArray::OCL_MAT)
{
vc_ >> frame_;
if(!frame_.empty())
{
arrCopy(frame_, _frame);
}
}
else if (_frame.isUMat())
vc_ >> *(UMat *)_frame.getObj();
else
{
//should never get here
// should never get here
CV_Assert(0);
}
}
......
......@@ -62,6 +62,23 @@ Mat cv::superres::arrGetMat(InputArray arr, Mat& buf)
}
}
UMat cv::superres::arrGetUMat(InputArray arr, UMat& buf)
{
switch (arr.kind())
{
case _InputArray::GPU_MAT:
arr.getGpuMat().download(buf);
return buf;
case _InputArray::OPENGL_BUFFER:
arr.getOGlBuffer().copyTo(buf);
return buf;
default:
return arr.getUMat();
}
}
GpuMat cv::superres::arrGetGpuMat(InputArray arr, GpuMat& buf)
{
switch (arr.kind())
......@@ -108,62 +125,39 @@ namespace
{
src.getGpuMat().copyTo(dst.getGpuMatRef());
}
#ifdef HAVE_OPENCV_OCL
void ocl2mat(InputArray src, OutputArray dst)
{
dst.getMatRef() = (Mat)ocl::getOclMatRef(src);
}
void mat2ocl(InputArray src, OutputArray dst)
{
Mat m = src.getMat();
ocl::getOclMatRef(dst) = (ocl::oclMat)m;
}
void ocl2ocl(InputArray src, OutputArray dst)
{
ocl::getOclMatRef(src).copyTo(ocl::getOclMatRef(dst));
}
#else
void ocl2mat(InputArray, OutputArray)
{
CV_Error(Error::StsNotImplemented, "The called functionality is disabled for current build or platform");;
}
void mat2ocl(InputArray, OutputArray)
{
CV_Error(Error::StsNotImplemented, "The called functionality is disabled for current build or platform");;
}
void ocl2ocl(InputArray, OutputArray)
{
CV_Error(Error::StsNotImplemented, "The called functionality is disabled for current build or platform");
}
#endif
}
void cv::superres::arrCopy(InputArray src, OutputArray dst)
{
if (dst.isUMat() || src.isUMat())
{
src.copyTo(dst);
return;
}
typedef void (*func_t)(InputArray src, OutputArray dst);
static const func_t funcs[11][11] =
static const func_t funcs[10][10] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0 /*arr2tex*/, mat2gpu, mat2ocl},
{0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, 0 /*buf2arr*/, buf2arr, 0 },
{0, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0 /*tex2arr*/, 0},
{0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, 0 /*arr2tex*/, gpu2gpu, 0 },
{0, ocl2mat, ocl2mat, ocl2mat, ocl2mat, ocl2mat, ocl2mat, 0, 0, 0, ocl2ocl}
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, 0, mat2gpu },
{ 0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, 0, buf2arr },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, 0 , gpu2gpu },
};
const int src_kind = src.kind() >> _InputArray::KIND_SHIFT;
const int dst_kind = dst.kind() >> _InputArray::KIND_SHIFT;
CV_DbgAssert( src_kind >= 0 && src_kind < 11 );
CV_DbgAssert( dst_kind >= 0 && dst_kind < 11 );
CV_Assert( src_kind >= 0 && src_kind < 10 );
CV_Assert( dst_kind >= 0 && dst_kind < 10 );
const func_t func = funcs[src_kind][dst_kind];
CV_DbgAssert( func != 0 );
CV_Assert( func != 0 );
func(src, dst);
}
......@@ -172,20 +166,21 @@ namespace
{
void convertToCn(InputArray src, OutputArray dst, int cn)
{
CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 );
int scn = src.channels();
CV_Assert( scn == 1 || scn == 3 || scn == 4 );
CV_Assert( cn == 1 || cn == 3 || cn == 4 );
static const int codes[5][5] =
{
{-1, -1, -1, -1, -1},
{-1, -1, -1, COLOR_GRAY2BGR, COLOR_GRAY2BGRA},
{-1, -1, -1, -1, -1},
{-1, COLOR_BGR2GRAY, -1, -1, COLOR_BGR2BGRA},
{-1, COLOR_BGRA2GRAY, -1, COLOR_BGRA2BGR, -1},
{ -1, -1, -1, -1, -1 },
{ -1, -1, -1, COLOR_GRAY2BGR, COLOR_GRAY2BGRA },
{ -1, -1, -1, -1, -1 },
{ -1, COLOR_BGR2GRAY, -1, -1, COLOR_BGR2BGRA },
{ -1, COLOR_BGRA2GRAY, -1, COLOR_BGRA2BGR, -1 }
};
const int code = codes[src.channels()][cn];
CV_DbgAssert( code >= 0 );
const int code = codes[scn][cn];
CV_Assert( code >= 0 );
switch (src.kind())
{
......@@ -202,6 +197,7 @@ namespace
break;
}
}
void convertToDepth(InputArray src, OutputArray dst, int depth)
{
CV_Assert( src.depth() <= CV_64F );
......@@ -226,6 +222,11 @@ namespace
src.getGpuMat().convertTo(dst.getGpuMatRef(), depth, scale);
break;
case _InputArray::UMAT:
case _InputArray::UEXPR:
src.getUMat().convertTo(dst, depth, scale);
break;
default:
src.getMat().convertTo(dst, depth, scale);
break;
......@@ -258,7 +259,7 @@ Mat cv::superres::convertToType(const Mat& src, int type, Mat& buf0, Mat& buf1)
return buf1;
}
GpuMat cv::superres::convertToType(const GpuMat& src, int type, GpuMat& buf0, GpuMat& buf1)
UMat cv::superres::convertToType(const UMat& src, int type, UMat& buf0, UMat& buf1)
{
if (src.type() == type)
return src;
......@@ -282,49 +283,8 @@ GpuMat cv::superres::convertToType(const GpuMat& src, int type, GpuMat& buf0, Gp
convertToDepth(buf0, buf1, depth);
return buf1;
}
#ifdef HAVE_OPENCV_OCL
namespace
{
// TODO(pengx17): remove these overloaded functions until IntputArray fully supports oclMat
void convertToCn(const ocl::oclMat& src, ocl::oclMat& dst, int cn)
{
CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 );
CV_Assert( cn == 1 || cn == 3 || cn == 4 );
static const int codes[5][5] =
{
{-1, -1, -1, -1, -1},
{-1, -1, -1, COLOR_GRAY2BGR, COLOR_GRAY2BGRA},
{-1, -1, -1, -1, -1},
{-1, COLOR_BGR2GRAY, -1, -1, COLOR_BGR2BGRA},
{-1, COLOR_BGRA2GRAY, -1, COLOR_BGRA2BGR, -1},
};
const int code = codes[src.channels()][cn];
CV_DbgAssert( code >= 0 );
ocl::cvtColor(src, dst, code, cn);
}
void convertToDepth(const ocl::oclMat& src, ocl::oclMat& dst, int depth)
{
CV_Assert( src.depth() <= CV_64F );
CV_Assert( depth == CV_8U || depth == CV_32F );
static const double maxVals[] =
{
std::numeric_limits<uchar>::max(),
std::numeric_limits<schar>::max(),
std::numeric_limits<ushort>::max(),
std::numeric_limits<short>::max(),
std::numeric_limits<int>::max(),
1.0,
1.0,
};
const double scale = maxVals[depth] / maxVals[src.depth()];
src.convertTo(dst, depth, scale);
}
}
ocl::oclMat cv::superres::convertToType(const ocl::oclMat& src, int type, ocl::oclMat& buf0, ocl::oclMat& buf1)
GpuMat cv::superres::convertToType(const GpuMat& src, int type, GpuMat& buf0, GpuMat& buf1)
{
if (src.type() == type)
return src;
......@@ -348,4 +308,3 @@ ocl::oclMat cv::superres::convertToType(const ocl::oclMat& src, int type, ocl::o
convertToDepth(buf0, buf1, depth);
return buf1;
}
#endif
......@@ -45,25 +45,20 @@
#include "opencv2/core.hpp"
#include "opencv2/core/cuda.hpp"
#ifdef HAVE_OPENCV_OCL
#include "opencv2/ocl.hpp"
#endif
namespace cv
{
namespace superres
{
CV_EXPORTS Mat arrGetMat(InputArray arr, Mat& buf);
CV_EXPORTS UMat arrGetUMat(InputArray arr, UMat& buf);
CV_EXPORTS cuda::GpuMat arrGetGpuMat(InputArray arr, cuda::GpuMat& buf);
CV_EXPORTS void arrCopy(InputArray src, OutputArray dst);
CV_EXPORTS Mat convertToType(const Mat& src, int type, Mat& buf0, Mat& buf1);
CV_EXPORTS UMat convertToType(const UMat& src, int type, UMat& buf0, UMat& buf1);
CV_EXPORTS cuda::GpuMat convertToType(const cuda::GpuMat& src, int type, cuda::GpuMat& buf0, cuda::GpuMat& buf1);
#ifdef HAVE_OPENCV_OCL
CV_EXPORTS ocl::oclMat convertToType(const ocl::oclMat& src, int type, ocl::oclMat& buf0, ocl::oclMat& buf1);
#endif
}
}
......
This diff is collapsed.
......@@ -82,10 +82,6 @@
# include "opencv2/cudacodec.hpp"
#endif
#ifdef HAVE_OPENCV_OCL
#include "opencv2/ocl/private/util.hpp"
#endif
#ifdef HAVE_OPENCV_HIGHGUI
#include "opencv2/highgui.hpp"
#endif
......
......@@ -54,16 +54,20 @@ cv::superres::SuperResolution::SuperResolution()
{
frameSource_ = createFrameSource_Empty();
firstCall_ = true;
isUmat_ = false;
}
void cv::superres::SuperResolution::setInput(const Ptr<FrameSource>& frameSource)
{
frameSource_ = frameSource;
firstCall_ = true;
isUmat_ = false;
}
void cv::superres::SuperResolution::nextFrame(OutputArray frame)
{
isUmat_ = frame.isUMat();
if (firstCall_)
{
initImpl(frameSource_);
......@@ -77,6 +81,7 @@ void cv::superres::SuperResolution::reset()
{
frameSource_->reset();
firstCall_ = true;
isUmat_ = false;
}
void cv::superres::SuperResolution::collectGarbage()
......
......@@ -41,6 +41,7 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
class AllignedFrameSource : public cv::superres::FrameSource
{
......@@ -52,6 +53,7 @@ public:
private:
cv::Ptr<cv::superres::FrameSource> base_;
cv::Mat origFrame_;
int scale_;
};
......@@ -67,9 +69,7 @@ void AllignedFrameSource::nextFrame(cv::OutputArray frame)
base_->nextFrame(origFrame_);
if (origFrame_.rows % scale_ == 0 && origFrame_.cols % scale_ == 0)
{
cv::superres::arrCopy(origFrame_, frame);
}
else
{
cv::Rect ROI(0, 0, (origFrame_.cols / scale_) * scale_, (origFrame_.rows / scale_) * scale_);
......@@ -92,6 +92,7 @@ public:
private:
cv::Ptr<cv::superres::FrameSource> base_;
cv::Mat origFrame_;
cv::Mat blurred_;
cv::Mat deg_;
......@@ -104,28 +105,25 @@ DegradeFrameSource::DegradeFrameSource(const cv::Ptr<cv::superres::FrameSource>&
CV_Assert( base_ );
}
void addGaussNoise(cv::Mat& image, double sigma)
static void addGaussNoise(cv::OutputArray _image, double sigma)
{
cv::Mat noise(image.size(), CV_32FC(image.channels()));
int type = _image.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
cv::Mat noise(_image.size(), CV_32FC(cn));
cvtest::TS::ptr()->get_rng().fill(noise, cv::RNG::NORMAL, 0.0, sigma);
cv::addWeighted(image, 1.0, noise, 1.0, 0.0, image, image.depth());
cv::addWeighted(_image, 1.0, noise, 1.0, 0.0, _image, depth);
}
void addSpikeNoise(cv::Mat& image, int frequency)
static void addSpikeNoise(cv::OutputArray _image, int frequency)
{
cv::Mat_<uchar> mask(image.size(), 0);
cv::Mat_<uchar> mask(_image.size(), 0);
for (int y = 0; y < mask.rows; ++y)
{
for (int x = 0; x < mask.cols; ++x)
{
if (cvtest::TS::ptr()->get_rng().uniform(0, frequency) < 1)
mask(y, x) = 255;
}
}
image.setTo(cv::Scalar::all(255), mask);
_image.setTo(cv::Scalar::all(255), mask);
}
void DegradeFrameSource::nextFrame(cv::OutputArray frame)
......@@ -146,7 +144,7 @@ void DegradeFrameSource::reset()
base_->reset();
}
double MSSIM(const cv::Mat& i1, const cv::Mat& i2)
double MSSIM(cv::InputArray _i1, cv::InputArray _i2)
{
const double C1 = 6.5025;
const double C2 = 58.5225;
......@@ -154,8 +152,8 @@ double MSSIM(const cv::Mat& i1, const cv::Mat& i2)
const int depth = CV_32F;
cv::Mat I1, I2;
i1.convertTo(I1, depth);
i2.convertTo(I2, depth);
_i1.getMat().convertTo(I1, depth);
_i2.getMat().convertTo(I2, depth);
cv::Mat I2_2 = I2.mul(I2); // I2^2
cv::Mat I1_2 = I1.mul(I1); // I1^2
......@@ -201,7 +199,7 @@ double MSSIM(const cv::Mat& i1, const cv::Mat& i2)
// mssim = average of ssim map
cv::Scalar mssim = cv::mean(ssim_map);
if (i1.channels() == 1)
if (_i1.channels() == 1)
return mssim[0];
return (mssim[0] + mssim[1] + mssim[3]) / 3;
......@@ -210,9 +208,11 @@ double MSSIM(const cv::Mat& i1, const cv::Mat& i2)
class SuperResolution : public testing::Test
{
public:
template <typename T>
void RunTest(cv::Ptr<cv::superres::SuperResolution> superRes);
};
template <typename T>
void SuperResolution::RunTest(cv::Ptr<cv::superres::SuperResolution> superRes)
{
const std::string inputVideoName = cvtest::TS::ptr()->get_data_path() + "car.avi";
......@@ -245,7 +245,8 @@ void SuperResolution::RunTest(cv::Ptr<cv::superres::SuperResolution> superRes)
double srAvgMSSIM = 0.0;
const int count = 10;
cv::Mat goldFrame, superResFrame;
cv::Mat goldFrame;
T superResFrame;
for (int i = 0; i < count; ++i)
{
goldSource->nextFrame(goldFrame);
......@@ -266,24 +267,28 @@ void SuperResolution::RunTest(cv::Ptr<cv::superres::SuperResolution> superRes)
TEST_F(SuperResolution, BTVL1)
{
RunTest(cv::superres::createSuperResolution_BTVL1());
RunTest<cv::Mat>(cv::superres::createSuperResolution_BTVL1());
}
#if defined(HAVE_CUDA) && defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAWARPING) && defined(HAVE_OPENCV_CUDAFILTERS)
TEST_F(SuperResolution, BTVL1_CUDA)
{
RunTest(cv::superres::createSuperResolution_BTVL1_CUDA());
RunTest<cv::Mat>(cv::superres::createSuperResolution_BTVL1_CUDA());
}
#endif
#if defined(HAVE_OPENCV_OCL) && defined(HAVE_OPENCL)
#ifdef HAVE_OPENCL
TEST_F(SuperResolution, BTVL1_OCL)
namespace cvtest {
namespace ocl {
OCL_TEST_F(SuperResolution, BTVL1)
{
if (cv::ocl::useOpenCL())
RunTest(cv::superres::createSuperResolution_BTVL1_OCL());
RunTest<cv::UMat>(cv::superres::createSuperResolution_BTVL1());
}
} } // namespace cvtest::ocl
#endif
......@@ -99,10 +99,14 @@ using std::tr1::tuple;
#define OCL_TEST_CYCLE() \
for (cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer())
#define OCL_TEST_CYCLE_N(n) \
for(declare.iterations(n), cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer())
#define OCL_TEST_CYCLE_MULTIRUN(runsNum) \
for (declare.runs(runsNum), cvtest::ocl::perf::safeFinish(); startTimer(), next(); cvtest::ocl::perf::safeFinish(), stopTimer()) \
for (int r = 0; r < runsNum; cvtest::ocl::perf::safeFinish(), ++r)
namespace perf {
// Check for current device limitation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment