1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Add super resolution's OpenCL implementation.

Accuracy and performance tests are also provided.
This commit is contained in:
peng xiao
2013-06-26 08:43:23 +08:00
parent c244f000ab
commit 9b3c318e85
12 changed files with 1483 additions and 16 deletions
+108 -13
View File
@@ -125,30 +125,59 @@ 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(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");;
}
void mat2ocl(InputArray, OutputArray)
{
CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");;
}
void ocl2ocl(InputArray, OutputArray)
{
CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
}
#endif
}
void cv::superres::arrCopy(InputArray src, OutputArray dst)
{
typedef void (*func_t)(InputArray src, OutputArray dst);
static const func_t funcs[10][10] =
static const func_t funcs[11][11] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu},
{0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr},
{0, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr},
{0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, arr2tex, gpu2gpu}
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, mat2mat, arr2buf, arr2tex, mat2gpu, mat2ocl},
{0, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, buf2arr, 0 },
{0, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, tex2arr, 0 },
{0, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, gpu2mat, arr2buf, arr2tex, gpu2gpu, 0 },
{0, ocl2mat, ocl2mat, ocl2mat, ocl2mat, ocl2mat, ocl2mat, 0, 0, 0, ocl2ocl}
};
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 < 10 );
CV_DbgAssert( dst_kind >= 0 && dst_kind < 10 );
CV_DbgAssert( src_kind >= 0 && src_kind < 11 );
CV_DbgAssert( dst_kind >= 0 && dst_kind < 11 );
const func_t func = funcs[src_kind][dst_kind];
CV_DbgAssert( func != 0 );
@@ -190,7 +219,6 @@ namespace
break;
}
}
void convertToDepth(InputArray src, OutputArray dst, int depth)
{
CV_Assert( src.depth() <= CV_64F );
@@ -271,3 +299,70 @@ 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)
{
if (src.type() == type)
return src;
const int depth = CV_MAT_DEPTH(type);
const int cn = CV_MAT_CN(type);
if (src.depth() == depth)
{
convertToCn(src, buf0, cn);
return buf0;
}
if (src.channels() == cn)
{
convertToDepth(src, buf1, depth);
return buf1;
}
convertToCn(src, buf0, cn);
convertToDepth(buf0, buf1, depth);
return buf1;
}
#endif