Commit 695b2017 authored by Rostislav Vasilikhin's avatar Rostislav Vasilikhin Committed by Alexander Alekhin

Merge pull request #7794 from savuor:fix/ovx_cvt_continuous

Fixed OpenVX wrapper for Mat::convertTo() (#7794)

* fixed for cases of unrolled (w*h x 1) matrices

* more error handling
parent cb46946d
...@@ -4641,26 +4641,45 @@ cvtScaleHalf_<short, float>( const short* src, size_t sstep, float* dst, size_t ...@@ -4641,26 +4641,45 @@ cvtScaleHalf_<short, float>( const short* src, size_t sstep, float* dst, size_t
} }
#ifdef HAVE_OPENVX #ifdef HAVE_OPENVX
#ifdef _DEBUG
#define VX_DbgThrow(s) CV_Error(cv::Error::StsInternal, (s))
#else
#define VX_DbgThrow(s) return false;
#endif
template<typename T, typename DT> template<typename T, typename DT>
static bool _openvx_cvt(const T* src, size_t sstep, static bool _openvx_cvt(const T* src, size_t sstep,
DT* dst, size_t dstep, Size size) DT* dst, size_t dstep, Size continuousSize)
{ {
using namespace ivx; using namespace ivx;
if(!(size.width > 0 && size.height > 0)) if(!(continuousSize.width > 0 && continuousSize.height > 0 && sstep > 0 && dstep > 0))
{ {
return true; return true;
} }
CV_Assert(sstep / sizeof(T) == dstep / sizeof(DT));
//.height is for number of continuous pieces
//.width is for length of one piece
Size imgSize = continuousSize;
if(continuousSize.height == 1)
{
//continuous case
imgSize.width = sstep / sizeof(T);
imgSize.height = continuousSize.width / (sstep / sizeof(T));
}
try try
{ {
Context context = Context::create(); Context context = Context::create();
Image srcImage = Image::createFromHandle(context, Image::matTypeToFormat(DataType<T>::type), Image srcImage = Image::createFromHandle(context, Image::matTypeToFormat(DataType<T>::type),
Image::createAddressing(size.width, size.height, Image::createAddressing(imgSize.width, imgSize.height,
(vx_uint32)sizeof(T), (vx_uint32)sstep), (vx_uint32)sizeof(T), (vx_uint32)sstep),
(void*)src); (void*)src);
Image dstImage = Image::createFromHandle(context, Image::matTypeToFormat(DataType<DT>::type), Image dstImage = Image::createFromHandle(context, Image::matTypeToFormat(DataType<DT>::type),
Image::createAddressing(size.width, size.height, Image::createAddressing(imgSize.width, imgSize.height,
(vx_uint32)sizeof(DT), (vx_uint32)dstep), (vx_uint32)sizeof(DT), (vx_uint32)dstep),
(void*)dst); (void*)dst);
...@@ -4674,13 +4693,11 @@ static bool _openvx_cvt(const T* src, size_t sstep, ...@@ -4674,13 +4693,11 @@ static bool _openvx_cvt(const T* src, size_t sstep,
} }
catch (RuntimeError & e) catch (RuntimeError & e)
{ {
CV_Error(CV_StsInternal, e.what()); VX_DbgThrow(e.what());
return false;
} }
catch (WrapperError & e) catch (WrapperError & e)
{ {
CV_Error(CV_StsInternal, e.what()); VX_DbgThrow(e.what());
return false;
} }
return true; return true;
......
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