Skip to content

Commit 0fef7f8

Browse files
Andrey PavlenkoOpenCV Buildbot
Andrey Pavlenko
authored and
OpenCV Buildbot
committed
Merge pull request opencv#2217 from ilya-lavrenov:tapi_superres
2 parents 13875b5 + 6ad4823 commit 0fef7f8

18 files changed

+861
-1474
lines changed

modules/core/include/opencv2/core/mat.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class CV_EXPORTS _OutputArray : public _InputArray
217217
virtual void createSameSize(const _InputArray& arr, int mtype) const;
218218
virtual void release() const;
219219
virtual void clear() const;
220-
virtual void setTo(const _InputArray& value) const;
220+
virtual void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
221221
};
222222

223223

modules/core/include/opencv2/core/opencl/ocl_defs.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
66
// Third party copyrights are property of their respective owners.
77

8+
//#define CV_OPENCL_RUN_VERBOSE
9+
810
#ifdef HAVE_OPENCL
911

1012
#ifdef CV_OPENCL_RUN_VERBOSE

modules/core/src/matrix.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ cuda::CudaMem& _OutputArray::getCudaMemRef() const
25602560
return *(cuda::CudaMem*)obj;
25612561
}
25622562

2563-
void _OutputArray::setTo(const _InputArray& arr) const
2563+
void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const
25642564
{
25652565
int k = kind();
25662566

@@ -2569,10 +2569,16 @@ void _OutputArray::setTo(const _InputArray& arr) const
25692569
else if( k == MAT || k == MATX || k == STD_VECTOR )
25702570
{
25712571
Mat m = getMat();
2572-
m.setTo(arr);
2572+
m.setTo(arr, mask);
25732573
}
25742574
else if( k == UMAT )
2575-
((UMat*)obj)->setTo(arr);
2575+
((UMat*)obj)->setTo(arr, mask);
2576+
else if( k == GPU_MAT )
2577+
{
2578+
Mat value = arr.getMat();
2579+
CV_Assert( checkScalar(value, type(), arr.kind(), _InputArray::GPU_MAT) );
2580+
((cuda::GpuMat*)obj)->setTo(Scalar(Vec<double, 4>((double *)value.data)), mask);
2581+
}
25762582
else
25772583
CV_Error(Error::StsNotImplemented, "");
25782584
}

modules/superres/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ endif()
55
set(the_description "Super Resolution")
66
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 -Wundef)
77
ocv_define_module(superres opencv_imgproc opencv_video
8-
OPTIONAL opencv_highgui opencv_ocl
9-
opencv_cudaarithm opencv_cudafilters opencv_cudawarping opencv_cudaimgproc opencv_cudaoptflow opencv_cudacodec)
8+
OPTIONAL opencv_highgui opencv_cudaarithm opencv_cudafilters opencv_cudawarping opencv_cudaimgproc opencv_cudaoptflow opencv_cudacodec)

modules/superres/include/opencv2/superres.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ namespace cv
8383
virtual void initImpl(Ptr<FrameSource>& frameSource) = 0;
8484
virtual void processImpl(Ptr<FrameSource>& frameSource, OutputArray output) = 0;
8585

86+
bool isUmat_;
87+
8688
private:
8789
Ptr<FrameSource> frameSource_;
8890
bool firstCall_;

modules/superres/perf/perf_superres.cpp

+51-16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//M*/
4242

4343
#include "perf_precomp.hpp"
44+
#include "opencv2/ts/ocl_perf.hpp"
4445

4546
using namespace std;
4647
using namespace std::tr1;
@@ -91,37 +92,26 @@ namespace
9192
class ZeroOpticalFlow : public DenseOpticalFlowExt
9293
{
9394
public:
94-
void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
95+
virtual void calc(InputArray frame0, InputArray, OutputArray flow1, OutputArray flow2)
9596
{
9697
cv::Size size = frame0.size();
9798

9899
if (!flow2.needed())
99100
{
100101
flow1.create(size, CV_32FC2);
101-
102-
if (flow1.kind() == cv::_InputArray::GPU_MAT)
103-
flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
104-
else
105-
flow1.getMatRef().setTo(cv::Scalar::all(0));
102+
flow1.setTo(cv::Scalar::all(0));
106103
}
107104
else
108105
{
109106
flow1.create(size, CV_32FC1);
110107
flow2.create(size, CV_32FC1);
111108

112-
if (flow1.kind() == cv::_InputArray::GPU_MAT)
113-
flow1.getGpuMatRef().setTo(cv::Scalar::all(0));
114-
else
115-
flow1.getMatRef().setTo(cv::Scalar::all(0));
116-
117-
if (flow2.kind() == cv::_InputArray::GPU_MAT)
118-
flow2.getGpuMatRef().setTo(cv::Scalar::all(0));
119-
else
120-
flow2.getMatRef().setTo(cv::Scalar::all(0));
109+
flow1.setTo(cv::Scalar::all(0));
110+
flow2.setTo(cv::Scalar::all(0));
121111
}
122112
}
123113

124-
void collectGarbage()
114+
virtual void collectGarbage()
125115
{
126116
}
127117
};
@@ -181,3 +171,48 @@ PERF_TEST_P(Size_MatType, SuperResolution_BTVL1,
181171
CPU_SANITY_CHECK(dst);
182172
}
183173
}
174+
175+
#ifdef HAVE_OPENCL
176+
177+
namespace cvtest {
178+
namespace ocl {
179+
180+
typedef Size_MatType SuperResolution_BTVL1;
181+
182+
OCL_PERF_TEST_P(SuperResolution_BTVL1 ,BTVL1,
183+
Combine(Values(szSmall64, szSmall128),
184+
Values(MatType(CV_8UC1), MatType(CV_8UC3))))
185+
{
186+
Size_MatType_t params = GetParam();
187+
const Size size = get<0>(params);
188+
const int type = get<1>(params);
189+
190+
Mat frame(size, type);
191+
UMat dst(1, 1, 0);
192+
declare.in(frame, WARMUP_RNG);
193+
194+
const int scale = 2;
195+
const int iterations = 50;
196+
const int temporalAreaRadius = 1;
197+
198+
Ptr<DenseOpticalFlowExt> opticalFlow(new ZeroOpticalFlow);
199+
Ptr<SuperResolution> superRes = createSuperResolution_BTVL1();
200+
201+
superRes->set("scale", scale);
202+
superRes->set("iterations", iterations);
203+
superRes->set("temporalAreaRadius", temporalAreaRadius);
204+
superRes->set("opticalFlow", opticalFlow);
205+
206+
superRes->setInput(makePtr<OneFrameSource_CPU>(frame));
207+
208+
// skip first frame
209+
superRes->nextFrame(dst);
210+
211+
OCL_TEST_CYCLE_N(10) superRes->nextFrame(dst);
212+
213+
SANITY_CHECK_NOTHING();
214+
}
215+
216+
} } // namespace cvtest::ocl
217+
218+
#endif // HAVE_OPENCL

modules/superres/perf/perf_superres_ocl.cpp

-143
This file was deleted.

0 commit comments

Comments
 (0)