Commit 055f41c9 authored by Andrey Pavlenko's avatar Andrey Pavlenko Committed by OpenCV Buildbot

Merge pull request #2250 from ilya-lavrenov:tapi_renaming

parents 564f5fcc 2e8579fe
......@@ -65,8 +65,8 @@ foreach(cl ${cl_list})
set(STR_CPP_DECL "const struct ProgramEntry ${cl_filename}={\"${cl_filename}\",\n\"${lines}, \"${hash}\"};\n")
set(STR_HPP_DECL "extern const struct ProgramEntry ${cl_filename};\n")
if(new_mode)
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource2 ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource2 ${cl_filename}_oclsrc;\n")
set(STR_CPP_DECL "${STR_CPP_DECL}ProgramSource ${cl_filename}_oclsrc(${cl_filename}.programStr);\n")
set(STR_HPP_DECL "${STR_HPP_DECL}extern ProgramSource ${cl_filename}_oclsrc;\n")
endif()
set(STR_CPP "${STR_CPP}${STR_CPP_DECL}")
......
......@@ -67,10 +67,10 @@ namespace ocl {
using namespace cv::ocl;
// TODO static functions in the Context class
CV_EXPORTS Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);
CV_EXPORTS Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);
CV_EXPORTS Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);
CV_EXPORTS Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);
CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);
CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);
CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);
CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);
} // namespace cv::directx::ocl
......
......@@ -85,10 +85,9 @@ public:
OPENGL_BUFFER = 7 << KIND_SHIFT,
CUDA_MEM = 8 << KIND_SHIFT,
GPU_MAT = 9 << KIND_SHIFT,
OCL_MAT =10 << KIND_SHIFT,
UMAT =11 << KIND_SHIFT,
STD_VECTOR_UMAT =12 << KIND_SHIFT,
UEXPR =13 << KIND_SHIFT
UMAT =10 << KIND_SHIFT,
STD_VECTOR_UMAT =11 << KIND_SHIFT,
UEXPR =12 << KIND_SHIFT
};
_InputArray();
......
......@@ -51,15 +51,15 @@ CV_EXPORTS bool useOpenCL();
CV_EXPORTS bool haveAmdBlas();
CV_EXPORTS bool haveAmdFft();
CV_EXPORTS void setUseOpenCL(bool flag);
CV_EXPORTS void finish2();
CV_EXPORTS void finish();
class CV_EXPORTS Context2;
class CV_EXPORTS Context;
class CV_EXPORTS Device;
class CV_EXPORTS Kernel;
class CV_EXPORTS Program;
class CV_EXPORTS ProgramSource2;
class CV_EXPORTS ProgramSource;
class CV_EXPORTS Queue;
class CV_EXPORTS PlatformInfo2;
class CV_EXPORTS PlatformInfo;
class CV_EXPORTS Image2D;
class CV_EXPORTS Device
......@@ -206,26 +206,26 @@ protected:
};
class CV_EXPORTS Context2
class CV_EXPORTS Context
{
public:
Context2();
explicit Context2(int dtype);
~Context2();
Context2(const Context2& c);
Context2& operator = (const Context2& c);
Context();
explicit Context(int dtype);
~Context();
Context(const Context& c);
Context& operator = (const Context& c);
bool create();
bool create(int dtype);
size_t ndevices() const;
const Device& device(size_t idx) const;
Program getProg(const ProgramSource2& prog,
Program getProg(const ProgramSource& prog,
const String& buildopt, String& errmsg);
static Context2& getDefault(bool initialize = true);
static Context& getDefault(bool initialize = true);
void* ptr() const;
friend void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device);
friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
protected:
struct Impl;
Impl* p;
......@@ -242,25 +242,25 @@ public:
void* ptr() const;
static Platform& getDefault();
friend void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device);
friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
protected:
struct Impl;
Impl* p;
};
// TODO Move to internal header
void initializeContextFromHandle(Context2& ctx, void* platform, void* context, void* device);
void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
class CV_EXPORTS Queue
{
public:
Queue();
explicit Queue(const Context2& c, const Device& d=Device());
explicit Queue(const Context& c, const Device& d=Device());
~Queue();
Queue(const Queue& q);
Queue& operator = (const Queue& q);
bool create(const Context2& c=Context2(), const Device& d=Device());
bool create(const Context& c=Context(), const Device& d=Device());
void finish();
void* ptr() const;
static Queue& getDefault();
......@@ -314,7 +314,7 @@ class CV_EXPORTS Kernel
public:
Kernel();
Kernel(const char* kname, const Program& prog);
Kernel(const char* kname, const ProgramSource2& prog,
Kernel(const char* kname, const ProgramSource& prog,
const String& buildopts = String(), String* errmsg=0);
~Kernel();
Kernel(const Kernel& k);
......@@ -322,7 +322,7 @@ public:
bool empty() const;
bool create(const char* kname, const Program& prog);
bool create(const char* kname, const ProgramSource2& prog,
bool create(const char* kname, const ProgramSource& prog,
const String& buildopts, String* errmsg=0);
int set(int i, const void* value, size_t sz);
......@@ -508,7 +508,7 @@ class CV_EXPORTS Program
{
public:
Program();
Program(const ProgramSource2& src,
Program(const ProgramSource& src,
const String& buildflags, String& errmsg);
explicit Program(const String& buf);
Program(const Program& prog);
......@@ -516,12 +516,12 @@ public:
Program& operator = (const Program& prog);
~Program();
bool create(const ProgramSource2& src,
bool create(const ProgramSource& src,
const String& buildflags, String& errmsg);
bool read(const String& buf, const String& buildflags);
bool write(String& buf) const;
const ProgramSource2& source() const;
const ProgramSource& source() const;
void* ptr() const;
String getPrefix() const;
......@@ -533,17 +533,17 @@ protected:
};
class CV_EXPORTS ProgramSource2
class CV_EXPORTS ProgramSource
{
public:
typedef uint64 hash_t;
ProgramSource2();
explicit ProgramSource2(const String& prog);
explicit ProgramSource2(const char* prog);
~ProgramSource2();
ProgramSource2(const ProgramSource2& prog);
ProgramSource2& operator = (const ProgramSource2& prog);
ProgramSource();
explicit ProgramSource(const String& prog);
explicit ProgramSource(const char* prog);
~ProgramSource();
ProgramSource(const ProgramSource& prog);
ProgramSource& operator = (const ProgramSource& prog);
const String& source() const;
hash_t hash() const;
......@@ -553,15 +553,15 @@ protected:
Impl* p;
};
class CV_EXPORTS PlatformInfo2
class CV_EXPORTS PlatformInfo
{
public:
PlatformInfo2();
explicit PlatformInfo2(void* id);
~PlatformInfo2();
PlatformInfo();
explicit PlatformInfo(void* id);
~PlatformInfo();
PlatformInfo2(const PlatformInfo2& i);
PlatformInfo2& operator =(const PlatformInfo2& i);
PlatformInfo(const PlatformInfo& i);
PlatformInfo& operator =(const PlatformInfo& i);
String name() const;
String vendor() const;
......@@ -578,7 +578,7 @@ CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf)
CV_EXPORTS const char* typeToStr(int t);
CV_EXPORTS const char* memopTypeToStr(int t);
CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1);
CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo2>& platform_info);
CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
class CV_EXPORTS Image2D
{
......
......@@ -236,7 +236,7 @@ namespace ocl {
static bool g_isDirect3DDevice9Ex = false; // Direct3DDevice9Ex or Direct3DDevice9 was used
#endif
Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
{
(void)pD3D11Device;
#if !defined(HAVE_DIRECTX)
......@@ -338,13 +338,13 @@ Context2& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device)
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
return ctx;
#endif
}
Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
{
(void)pD3D10Device;
#if !defined(HAVE_DIRECTX)
......@@ -446,13 +446,13 @@ Context2& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device)
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
return ctx;
#endif
}
Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex)
Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex)
{
(void)pDirect3DDevice9Ex;
#if !defined(HAVE_DIRECTX)
......@@ -555,14 +555,14 @@ Context2& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDe
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop");
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = true;
return ctx;
#endif
}
Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9)
Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9)
{
(void)pDirect3DDevice9;
#if !defined(HAVE_DIRECTX)
......@@ -665,7 +665,7 @@ Context2& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't create context for DirectX interop");
}
Context2& ctx = Context2::getDefault(false);
Context& ctx = Context::getDefault(false);
initializeContextFromHandle(ctx, platforms[found], context, device);
g_isDirect3DDevice9Ex = false;
return ctx;
......@@ -720,7 +720,7 @@ void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D)
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
......@@ -777,7 +777,7 @@ void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst
CV_Assert(textureType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
......@@ -868,7 +868,7 @@ void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D)
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
......@@ -925,7 +925,7 @@ void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst
CV_Assert(textureType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
......@@ -1019,7 +1019,7 @@ void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurfa
CV_Assert(srcSize.width == (int)desc.Width && srcSize.height == (int)desc.Height);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
UMat u = src.getUMat();
......@@ -1083,7 +1083,7 @@ void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArr
CV_Assert(surfaceType >= 0);
using namespace cv::ocl;
Context2& ctx = Context2::getDefault();
Context& ctx = Context::getDefault();
cl_context context = (cl_context)ctx.ptr();
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
......
......@@ -1545,7 +1545,7 @@ class PlanCache
clStridesOut[2] = dft_rows ? clStridesOut[1] : dft_size.width * clStridesOut[1];
// TODO remove all plans if context changed
CLAMDDFT_Assert(clAmdFftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context2::getDefault().ptr(), dim, clLengthsIn))
CLAMDDFT_Assert(clAmdFftCreateDefaultPlan(&plHandle, (cl_context)ocl::Context::getDefault().ptr(), dim, clLengthsIn))
// setting plan properties
CLAMDDFT_Assert(clAmdFftSetPlanPrecision(plHandle, doubleFP ? CLFFT_DOUBLE : CLFFT_SINGLE));
......@@ -1560,8 +1560,8 @@ class PlanCache
CLAMDDFT_Assert(clAmdFftSetPlanScale(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD, scale))
// ready to bake
cl_command_queue commandQueue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &commandQueue, NULL, NULL))
cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
CLAMDDFT_Assert(clAmdFftBakePlan(plHandle, 1, &queue, NULL, NULL))
}
~FftPlan()
......@@ -1593,7 +1593,7 @@ public:
clAmdFftPlanHandle getPlanHandle(const Size & dft_size, int src_step, int dst_step, bool doubleFP,
bool inplace, int flags, FftType fftType)
{
cl_context currentContext = (cl_context)ocl::Context2::getDefault().ptr();
cl_context currentContext = (cl_context)ocl::Context::getDefault().ptr();
for (size_t i = 0, size = planStorage.size(); i < size; i ++)
{
......@@ -1704,11 +1704,11 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags)
cl_mem srcarg = (cl_mem)src.handle(ACCESS_READ);
cl_mem dstarg = (cl_mem)dst.handle(ACCESS_RW);
cl_command_queue commandQueue = (cl_command_queue)ocl::Queue::getDefault().ptr();
cl_command_queue queue = (cl_command_queue)ocl::Queue::getDefault().ptr();
cl_event e = 0;
CLAMDDFT_Assert(clAmdFftEnqueueTransform(plHandle, dft_inverse ? CLFFT_BACKWARD : CLFFT_FORWARD,
1, &commandQueue, 0, NULL, &e,
1, &queue, 0, NULL, &e,
&srcarg, &dstarg, (cl_mem)tmpBuffer.handle(ACCESS_RW)))
tmpBuffer.addref();
......
......@@ -1495,11 +1495,6 @@ Size _InputArray::size(int i) const
return d_mat->size();
}
if( k == OCL_MAT )
{
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet");
}
CV_Assert( k == CUDA_MEM );
//if( k == CUDA_MEM )
{
......@@ -1679,11 +1674,6 @@ int _InputArray::dims(int i) const
return 2;
}
if( k == OCL_MAT )
{
return 2;
}
CV_Assert( k == CUDA_MEM );
//if( k == CUDA_MEM )
{
......@@ -1841,11 +1831,6 @@ bool _InputArray::empty() const
if( k == OPENGL_BUFFER )
return ((const ogl::Buffer*)obj)->empty();
if( k == OCL_MAT )
{
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet");
}
if( k == GPU_MAT )
return ((const cuda::GpuMat*)obj)->empty();
......@@ -1881,7 +1866,7 @@ bool _InputArray::isContinuous(int i) const
return vv[i].isContinuous();
}
CV_Error(CV_StsNotImplemented, "This method is not implemented for oclMat yet");
CV_Error(CV_StsNotImplemented, "Unknown/unsupported array type");
return false;
}
......
This diff is collapsed.
......@@ -25,7 +25,7 @@
//
// * 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 oclMaterials provided with the distribution.
// 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.
......
......@@ -3900,7 +3900,7 @@ static bool ocl_warpTransform(InputArray _src, OutputArray _dst, InputArray _M0,
return false;
const char * const interpolationMap[3] = { "NEAREST", "LINEAR", "CUBIC" };
ocl::ProgramSource2 program = op_type == OCL_OP_AFFINE ?
ocl::ProgramSource program = op_type == OCL_OP_AFFINE ?
ocl::imgproc::warp_affine_oclsrc : ocl::imgproc::warp_perspective_oclsrc;
const char * const kernelName = op_type == OCL_OP_AFFINE ? "warpAffine" : "warpPerspective";
......
......@@ -407,8 +407,7 @@ static bool ocl_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, in
{
int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
if (((channels != 1) && (channels != 2) && (channels != 4))
|| (borderType != BORDER_DEFAULT))
if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
return false;
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
......@@ -425,18 +424,16 @@ static bool ocl_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, in
_dst.create( dsize, src.type() );
UMat dst = _dst.getUMat();
const char * const kernelName = "pyrDown";
ocl::ProgramSource2 program = ocl::imgproc::pyr_down_oclsrc;
ocl::Kernel k;
int float_depth = depth == CV_64F ? CV_64F : CV_32F;
char cvt[2][50];
k.create(kernelName, program,
ocl::Kernel k("pyrDown", ocl::imgproc::pyr_down_oclsrc,
format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst));
......@@ -449,12 +446,11 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
{
int type = _src.type(), depth = CV_MAT_DEPTH(type), channels = CV_MAT_CN(type);
if (((channels != 1) && (channels != 2) && (channels != 4))
|| (borderType != BORDER_DEFAULT))
if ((channels != 1 && channels != 2 && channels != 4) || borderType != BORDER_DEFAULT)
return false;
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;
if ((depth == CV_64F) && !(doubleSupport))
if (depth == CV_64F && !doubleSupport)
return false;
Size ssize = _src.size();
......@@ -466,18 +462,16 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
_dst.create( dsize, src.type() );
UMat dst = _dst.getUMat();
const char * const kernelName = "pyrUp";
ocl::ProgramSource2 program = ocl::imgproc::pyr_up_oclsrc;
ocl::Kernel k;
int float_depth = depth == CV_64F ? CV_64F : CV_32F;
char cvt[2][50];
k.create(kernelName, program,
ocl::Kernel k("pyrUp", ocl::imgproc::pyr_up_oclsrc,
format("-D T=%s -D FT=%s -D convertToT=%s -D convertToFT=%s%s",
ocl::typeToStr(type), ocl::typeToStr(CV_MAKETYPE(float_depth, channels)),
ocl::convertTypeStr(float_depth, depth, channels, cvt[0]),
ocl::convertTypeStr(depth, float_depth, channels, cvt[1]),
doubleSupport ? " -D DOUBLE_SUPPORT" : ""));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst));
size_t globalThreads[2] = {dst.cols, dst.rows};
......
......@@ -119,7 +119,7 @@ CV_EXPORTS void randu(InputOutputArray dst);
inline void safeFinish()
{
if (cv::ocl::useOpenCL())
cv::ocl::finish2();
cv::ocl::finish();
}
} // namespace perf
......
......@@ -98,14 +98,14 @@ void dumpOpenCLDevice()
using namespace cv::ocl;
try
{
std::vector<PlatformInfo2> platforms;
std::vector<PlatformInfo> platforms;
cv::ocl::getPlatfomsInfo(platforms);
if (platforms.size() > 0)
{
DUMP_MESSAGE_STDOUT("OpenCL Platforms: ");
for (size_t i = 0; i < platforms.size(); i++)
{
const PlatformInfo2* platform = &platforms[i];
const PlatformInfo* platform = &platforms[i];
DUMP_MESSAGE_STDOUT(" " << platform->name().c_str());
Device current_device;
for (int j = 0; j < platform->deviceNumber(); j++)
......
......@@ -134,7 +134,7 @@ static void renderToD3DObject(void)
const float fps = getFps();
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context2::getDefault().device(0).name() : "No OpenCL device";
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context::getDefault().device(0).name() : "No OpenCL device";
if ((frame % std::max(1, (int)(fps / 25))) == 0)
{
......@@ -360,7 +360,7 @@ static cv::Mat getInputTexture()
{
cv::resize(inputMat, inputMat, cv::Size(WIDTH, HEIGHT));
}
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context2::getDefault().device(0).name() : "No OpenCL device";
String deviceName = cv::ocl::useOpenCL() ? cv::ocl::Context::getDefault().device(0).name() : "No OpenCL device";
cv::Scalar color(64, 255, 64, 255);
cv::putText(inputMat,
cv::format("OpenCL Device name: %s", deviceName.c_str()),
......@@ -396,13 +396,13 @@ static int mainLoop()
if (cv::ocl::haveOpenCL())
{
#if defined(USE_D3D9)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9(dev);
#elif defined (USE_D3DEX)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromDirect3DDevice9Ex(dev);
#elif defined(USE_D3D10)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromD3D10Device(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D10Device(dev);
#elif defined(USE_D3D11)
cv::ocl::Context2& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev);
cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D11Device(dev);
#else
#error "Invalid USE_D3D value"
#endif
......
......@@ -10,14 +10,10 @@
#include "opencv2/superres/optical_flow.hpp"
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_OCL)
#include "opencv2/ocl/ocl.hpp"
#endif
using namespace std;
using namespace cv;
using namespace cv::superres;
bool useOclChanged;
#define MEASURE_TIME(op) \
{ \
TickMeter tm; \
......@@ -50,40 +46,11 @@ static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
else if (name == "pyrlk")
return createOptFlow_PyrLK_CUDA();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
return Ptr<DenseOpticalFlowExt>();
}
#if defined(HAVE_OPENCV_OCL)
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name)
{
if (name == "farneback")
{
return createOptFlow_Farneback_OCL();
}
else if (name == "simple")
{
useOclChanged = true;
std::cout<<"simple on OpenCL has not been implemented. Use CPU instead!\n";
return createOptFlow_Simple();
}
else if (name == "tvl1")
return createOptFlow_DualTVL1_OCL();
else if (name == "brox")
{
std::cout<<"brox has not been implemented!\n";
return Ptr<DenseOpticalFlowExt>();
}
else if (name == "pyrlk")
return createOptFlow_PyrLK_OCL();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
return Ptr<DenseOpticalFlowExt>();
}
#endif
int main(int argc, const char* argv[])
{
useOclChanged = false;
......@@ -94,7 +61,7 @@ int main(int argc, const char* argv[])
"{ i iterations | 180 | Iteration count }"
"{ t temporal | 4 | Radius of the temporal search area }"
"{ f flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }"
"{ g | false | CPU as default device, cuda for CUDA and ocl for OpenCL }"
"{ g | false | CPU as default device, cuda for CUDA }"
"{ h help | false | Print help message }"
);
......@@ -102,7 +69,7 @@ int main(int argc, const char* argv[])
{
cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl;
cmd.printMessage();
return 0;
return EXIT_SUCCESS;
}
const string inputVideoName = cmd.get<string>("video");
......@@ -115,60 +82,19 @@ int main(int argc, const char* argv[])
std::transform(gpuOption.begin(), gpuOption.end(), gpuOption.begin(), ::tolower);
bool useCuda = false;
bool useOcl = false;
if(gpuOption.compare("ocl") == 0)
useOcl = true;
else if(gpuOption.compare("cuda") == 0)
useCuda = true;
#ifndef HAVE_OPENCV_OCL
if(useOcl)
{
{
cout<<"OPENCL is not compiled\n";
return 0;
}
}
#endif
#if defined(HAVE_OPENCV_OCL)
if(useCuda)
{
CV_Assert(!useOcl);
}
#endif
bool useCuda = gpuOption.compare("cuda") == 0;
Ptr<SuperResolution> superRes;
#if defined(HAVE_OPENCV_OCL)
if(useOcl)
{
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow);
if (of.empty())
exit(-1);
if(useOclChanged)
{
superRes = createSuperResolution_BTVL1();
useOcl = !useOcl;
}else
superRes = createSuperResolution_BTVL1_OCL();
superRes->set("opticalFlow", of);
}
if (useCuda)
superRes = createSuperResolution_BTVL1_CUDA();
else
#endif
{
if (useCuda)
superRes = createSuperResolution_BTVL1_CUDA();
else
superRes = createSuperResolution_BTVL1();
superRes = createSuperResolution_BTVL1();
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
if (of.empty())
exit(-1);
superRes->set("opticalFlow", of);
}
if (of.empty())
return EXIT_FAILURE;
superRes->set("opticalFlow", of);
superRes->set("scale", scale);
superRes->set("iterations", iterations);
......@@ -201,11 +127,7 @@ int main(int argc, const char* argv[])
cout << "Iterations : " << iterations << endl;
cout << "Temporal radius : " << temporalAreaRadius << endl;
cout << "Optical Flow : " << optFlow << endl;
#if defined(HAVE_OPENCV_OCL)
cout << "Mode : " << (useCuda ? "CUDA" : useOcl? "OpenCL" : "CPU") << endl;
#else
cout << "Mode : " << (useCuda ? "CUDA" : "CPU") << endl;
#endif
}
superRes->setInput(frameSource);
......@@ -217,32 +139,8 @@ int main(int argc, const char* argv[])
cout << '[' << setw(3) << i << "] : ";
Mat result;
#if defined(HAVE_OPENCV_OCL)
cv::ocl::oclMat result_;
if(useOcl)
{
MEASURE_TIME(
{
superRes->nextFrame(result_);
ocl::finish();
});
}
else
#endif
{
MEASURE_TIME(superRes->nextFrame(result));
}
MEASURE_TIME(superRes->nextFrame(result));
#ifdef HAVE_OPENCV_OCL
if(useOcl)
{
if(!result_.empty())
{
result_.download(result);
}
}
#endif
if (result.empty())
break;
......
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