mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
used new device layer for cv::cuda::LUT
This commit is contained in:
@@ -130,217 +130,4 @@ void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& str
|
||||
funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// LUT
|
||||
|
||||
#if (CUDA_VERSION >= 5000)
|
||||
|
||||
namespace
|
||||
{
|
||||
class LookUpTableImpl : public LookUpTable
|
||||
{
|
||||
public:
|
||||
LookUpTableImpl(InputArray lut);
|
||||
|
||||
void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
|
||||
|
||||
private:
|
||||
int lut_cn;
|
||||
|
||||
int nValues3[3];
|
||||
const Npp32s* pValues3[3];
|
||||
const Npp32s* pLevels3[3];
|
||||
|
||||
GpuMat d_pLevels;
|
||||
GpuMat d_nppLut;
|
||||
GpuMat d_nppLut3[3];
|
||||
};
|
||||
|
||||
LookUpTableImpl::LookUpTableImpl(InputArray _lut)
|
||||
{
|
||||
nValues3[0] = nValues3[1] = nValues3[2] = 256;
|
||||
|
||||
Npp32s pLevels[256];
|
||||
for (int i = 0; i < 256; ++i)
|
||||
pLevels[i] = i;
|
||||
|
||||
d_pLevels.upload(Mat(1, 256, CV_32S, pLevels));
|
||||
pLevels3[0] = pLevels3[1] = pLevels3[2] = d_pLevels.ptr<Npp32s>();
|
||||
|
||||
GpuMat lut;
|
||||
if (_lut.kind() == _InputArray::GPU_MAT)
|
||||
{
|
||||
lut = _lut.getGpuMat();
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat hLut = _lut.getMat();
|
||||
CV_Assert( hLut.total() == 256 && hLut.isContinuous() );
|
||||
lut.upload(Mat(1, 256, hLut.type(), hLut.data));
|
||||
}
|
||||
|
||||
lut_cn = lut.channels();
|
||||
|
||||
CV_Assert( lut.depth() == CV_8U );
|
||||
CV_Assert( lut.rows == 1 && lut.cols == 256 );
|
||||
|
||||
lut.convertTo(d_nppLut, CV_32S);
|
||||
|
||||
if (lut_cn == 1)
|
||||
{
|
||||
pValues3[0] = pValues3[1] = pValues3[2] = d_nppLut.ptr<Npp32s>();
|
||||
}
|
||||
else
|
||||
{
|
||||
cuda::split(d_nppLut, d_nppLut3);
|
||||
|
||||
pValues3[0] = d_nppLut3[0].ptr<Npp32s>();
|
||||
pValues3[1] = d_nppLut3[1].ptr<Npp32s>();
|
||||
pValues3[2] = d_nppLut3[2].ptr<Npp32s>();
|
||||
}
|
||||
}
|
||||
|
||||
void LookUpTableImpl::transform(InputArray _src, OutputArray _dst, Stream& _stream)
|
||||
{
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_8UC3 );
|
||||
CV_Assert( lut_cn == 1 || lut_cn == cn );
|
||||
|
||||
_dst.create(src.size(), src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.height = src.rows;
|
||||
sz.width = src.cols;
|
||||
|
||||
if (src.type() == CV_8UC1)
|
||||
{
|
||||
nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, d_nppLut.ptr<Npp32s>(), d_pLevels.ptr<Npp32s>(), 256) );
|
||||
}
|
||||
else
|
||||
{
|
||||
nppSafeCall( nppiLUT_Linear_8u_C3R(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, pValues3, pLevels3, nValues3) );
|
||||
}
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
}
|
||||
|
||||
#else // (CUDA_VERSION >= 5000)
|
||||
|
||||
namespace
|
||||
{
|
||||
class LookUpTableImpl : public LookUpTable
|
||||
{
|
||||
public:
|
||||
LookUpTableImpl(InputArray lut);
|
||||
|
||||
void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
|
||||
|
||||
private:
|
||||
int lut_cn;
|
||||
|
||||
Npp32s pLevels[256];
|
||||
int nValues3[3];
|
||||
const Npp32s* pValues3[3];
|
||||
const Npp32s* pLevels3[3];
|
||||
|
||||
Mat nppLut;
|
||||
Mat nppLut3[3];
|
||||
};
|
||||
|
||||
LookUpTableImpl::LookUpTableImpl(InputArray _lut)
|
||||
{
|
||||
nValues3[0] = nValues3[1] = nValues3[2] = 256;
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
pLevels[i] = i;
|
||||
pLevels3[0] = pLevels3[1] = pLevels3[2] = pLevels;
|
||||
|
||||
Mat lut;
|
||||
if (_lut.kind() == _InputArray::GPU_MAT)
|
||||
{
|
||||
lut = Mat(_lut.getGpuMat());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat hLut = _lut.getMat();
|
||||
CV_Assert( hLut.total() == 256 && hLut.isContinuous() );
|
||||
lut = hLut;
|
||||
}
|
||||
|
||||
lut_cn = lut.channels();
|
||||
|
||||
CV_Assert( lut.depth() == CV_8U );
|
||||
CV_Assert( lut.rows == 1 && lut.cols == 256 );
|
||||
|
||||
lut.convertTo(nppLut, CV_32S);
|
||||
|
||||
if (lut_cn == 1)
|
||||
{
|
||||
pValues3[0] = pValues3[1] = pValues3[2] = nppLut.ptr<Npp32s>();
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::split(nppLut, nppLut3);
|
||||
|
||||
pValues3[0] = nppLut3[0].ptr<Npp32s>();
|
||||
pValues3[1] = nppLut3[1].ptr<Npp32s>();
|
||||
pValues3[2] = nppLut3[2].ptr<Npp32s>();
|
||||
}
|
||||
}
|
||||
|
||||
void LookUpTableImpl::transform(InputArray _src, OutputArray _dst, Stream& _stream)
|
||||
{
|
||||
GpuMat src = _src.getGpuMat();
|
||||
|
||||
const int cn = src.channels();
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_8UC3 );
|
||||
CV_Assert( lut_cn == 1 || lut_cn == cn );
|
||||
|
||||
_dst.create(src.size(), src.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
cudaStream_t stream = StreamAccessor::getStream(_stream);
|
||||
|
||||
NppStreamHandler h(stream);
|
||||
|
||||
NppiSize sz;
|
||||
sz.height = src.rows;
|
||||
sz.width = src.cols;
|
||||
|
||||
if (src.type() == CV_8UC1)
|
||||
{
|
||||
nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, nppLut.ptr<Npp32s>(), pLevels, 256) );
|
||||
}
|
||||
else
|
||||
{
|
||||
nppSafeCall( nppiLUT_Linear_8u_C3R(src.ptr<Npp8u>(), static_cast<int>(src.step),
|
||||
dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, pValues3, pLevels3, nValues3) );
|
||||
}
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // (CUDA_VERSION >= 5000)
|
||||
|
||||
Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray lut)
|
||||
{
|
||||
return makePtr<LookUpTableImpl>(lut);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
||||
Reference in New Issue
Block a user