cleaned up super_resolution sample from old OCL
This commit is contained in:
@@ -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_;
|
||||
MEASURE_TIME(superRes->nextFrame(result));
|
||||
|
||||
if(useOcl)
|
||||
{
|
||||
MEASURE_TIME(
|
||||
{
|
||||
superRes->nextFrame(result_);
|
||||
ocl::finish();
|
||||
});
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
MEASURE_TIME(superRes->nextFrame(result));
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_OCL
|
||||
if(useOcl)
|
||||
{
|
||||
if(!result_.empty())
|
||||
{
|
||||
result_.download(result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (result.empty())
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user