mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #7768 from terfendail:ovx_remap
This commit is contained in:
Vendored
+207
@@ -361,6 +361,15 @@ template <> struct RefTypeTraits <vx_distribution>
|
||||
static vx_status release(vxType& ref) { return vxReleaseDistribution(&ref); }
|
||||
};
|
||||
|
||||
class Remap;
|
||||
template <> struct RefTypeTraits <vx_remap>
|
||||
{
|
||||
typedef vx_remap vxType;
|
||||
typedef Remap wrapperType;
|
||||
static const vx_enum vxTypeEnum = VX_TYPE_REMAP;
|
||||
static vx_status release(vxType& ref) { return vxReleaseRemap(&ref); }
|
||||
};
|
||||
|
||||
#ifdef IVX_USE_CXX98
|
||||
|
||||
/// Casting to vx_reference with compile-time check
|
||||
@@ -918,6 +927,34 @@ public:
|
||||
void setImmediateBorder(vx_enum mode, const vx_pixel_value_t& val)
|
||||
{ border_t bm = {mode, val}; setImmediateBorder(bm); }
|
||||
|
||||
/// vxSetContextAttribute(BORDER) wrapper
|
||||
template <typename T>
|
||||
void setImmediateBorder(vx_enum mode, const T& _val)
|
||||
{
|
||||
vx_pixel_value_t val;
|
||||
switch (TypeToEnum<T>::value)
|
||||
{
|
||||
case VX_TYPE_UINT8:
|
||||
val.U8 = _val;
|
||||
break;
|
||||
case VX_TYPE_INT16:
|
||||
val.S16 = _val;
|
||||
break;
|
||||
case VX_TYPE_UINT16:
|
||||
val.U16 = _val;
|
||||
break;
|
||||
case VX_TYPE_INT32:
|
||||
val.S32 = _val;
|
||||
break;
|
||||
case VX_TYPE_UINT32:
|
||||
val.U32 = _val;
|
||||
break;
|
||||
default:
|
||||
throw WrapperError("Unsupported constant border value type");
|
||||
}
|
||||
setImmediateBorder(mode, val);
|
||||
}
|
||||
|
||||
/// vxSetContextAttribute(BORDER) wrapper
|
||||
void setImmediateBorder(vx_enum mode)
|
||||
{ vx_pixel_value_t val = {}; setImmediateBorder(mode, val); }
|
||||
@@ -1273,6 +1310,34 @@ static const vx_enum
|
||||
void setBorder(vx_enum mode, const vx_pixel_value_t& val)
|
||||
{ vx_border_t bm = {mode, val}; setBorder(bm); }
|
||||
|
||||
/// vxSetNodeAttribute(BORDER) wrapper
|
||||
template <typename T>
|
||||
void setBorder(vx_enum mode, const T& _val)
|
||||
{
|
||||
vx_pixel_value_t val;
|
||||
switch (TypeToEnum<T>::value)
|
||||
{
|
||||
case VX_TYPE_UINT8:
|
||||
val.U8 = _val;
|
||||
break;
|
||||
case VX_TYPE_INT16:
|
||||
val.S16 = _val;
|
||||
break;
|
||||
case VX_TYPE_UINT16:
|
||||
val.U16 = _val;
|
||||
break;
|
||||
case VX_TYPE_INT32:
|
||||
val.S32 = _val;
|
||||
break;
|
||||
case VX_TYPE_UINT32:
|
||||
val.U32 = _val;
|
||||
break;
|
||||
default:
|
||||
throw WrapperError("Unsupported constant border value type");
|
||||
}
|
||||
setBorder(mode, val);
|
||||
}
|
||||
|
||||
/// vxSetNodeAttribute(BORDER) wrapper
|
||||
void setBorder(vx_enum mode)
|
||||
{ vx_pixel_value_t val = {}; setBorder(mode, val); }
|
||||
@@ -2999,6 +3064,148 @@ public:
|
||||
#endif //IVX_USE_OPENCV
|
||||
};
|
||||
|
||||
/*
|
||||
* Remap
|
||||
*/
|
||||
class Remap : public RefWrapper<vx_remap>
|
||||
{
|
||||
public:
|
||||
IVX_REF_STD_CTORS_AND_ASSIGNMENT(Remap);
|
||||
|
||||
static Remap create(vx_context context, vx_uint32 src_width, vx_uint32 src_height, vx_uint32 dst_width, vx_uint32 dst_height)
|
||||
{
|
||||
return Remap(vxCreateRemap(context, src_width, src_height, dst_width, dst_height));
|
||||
}
|
||||
|
||||
#ifndef VX_VERSION_1_1
|
||||
static const vx_enum
|
||||
VX_REMAP_SOURCE_WIDTH = VX_REMAP_ATTRIBUTE_SOURCE_WIDTH,
|
||||
VX_REMAP_SOURCE_HEIGHT = VX_REMAP_ATTRIBUTE_SOURCE_HEIGHT,
|
||||
VX_REMAP_DESTINATION_WIDTH = VX_REMAP_ATTRIBUTE_DESTINATION_WIDTH,
|
||||
VX_REMAP_DESTINATION_HEIGHT = VX_REMAP_ATTRIBUTE_DESTINATION_HEIGHT;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
void query(vx_enum att, T& value) const
|
||||
{ IVX_CHECK_STATUS(vxQueryRemap(ref, att, &value, sizeof(value))); }
|
||||
|
||||
vx_uint32 srcWidth() const
|
||||
{
|
||||
vx_uint32 v;
|
||||
query(VX_REMAP_SOURCE_WIDTH, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
vx_uint32 srcHeight() const
|
||||
{
|
||||
vx_uint32 v;
|
||||
query(VX_REMAP_SOURCE_HEIGHT, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
vx_uint32 dstWidth() const
|
||||
{
|
||||
vx_uint32 v;
|
||||
query(VX_REMAP_DESTINATION_WIDTH, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
vx_uint32 dstHeight() const
|
||||
{
|
||||
vx_uint32 v;
|
||||
query(VX_REMAP_DESTINATION_HEIGHT, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
vx_uint32 srcCoordType() const
|
||||
{ return VX_TYPE_FLOAT32; }
|
||||
|
||||
vx_uint32 dstCoordType() const
|
||||
{ return VX_TYPE_UINT32; }
|
||||
|
||||
void setMapping(vx_uint32 dst_x, vx_uint32 dst_y, vx_float32 src_x, vx_float32 src_y)
|
||||
{ IVX_CHECK_STATUS(vxSetRemapPoint(ref, dst_x, dst_y, src_x, src_y)); }
|
||||
|
||||
void getMapping(vx_uint32 dst_x, vx_uint32 dst_y, vx_float32 &src_x, vx_float32 &src_y) const
|
||||
{ IVX_CHECK_STATUS(vxGetRemapPoint(ref, dst_x, dst_y, &src_x, &src_y)); }
|
||||
|
||||
#ifdef IVX_USE_OPENCV
|
||||
void setMappings(const cv::Mat& map_x, const cv::Mat& map_y)
|
||||
{
|
||||
if (map_x.type() != enumToCVType(srcCoordType()) || map_y.type() != enumToCVType(srcCoordType()))
|
||||
throw WrapperError(std::string(__func__) + "(): mapping type is wrong");
|
||||
if ((vx_uint32)(map_x.rows) != dstHeight() || (vx_uint32)(map_x.cols) != dstWidth())
|
||||
throw WrapperError(std::string(__func__) + "(): x mapping size is wrong");
|
||||
if ((vx_uint32)(map_y.rows) != dstHeight() || (vx_uint32)(map_y.cols) != dstWidth())
|
||||
throw WrapperError(std::string(__func__) + "(): y mapping size is wrong");
|
||||
|
||||
for (vx_uint32 y = 0; y < dstHeight(); y++)
|
||||
{
|
||||
const vx_float32* map_x_line = map_x.ptr<vx_float32>(y);
|
||||
const vx_float32* map_y_line = map_y.ptr<vx_float32>(y);
|
||||
for (vx_uint32 x = 0; x < dstWidth(); x++)
|
||||
setMapping(x, y, map_x_line[x], map_y_line[x]);
|
||||
}
|
||||
}
|
||||
|
||||
void setMappings(const cv::Mat& map)
|
||||
{
|
||||
if (map.depth() != CV_MAT_DEPTH(enumToCVType(srcCoordType())) || map.channels() != 2)
|
||||
throw WrapperError(std::string(__func__) + "(): mapping type is wrong");
|
||||
if ((vx_uint32)(map.rows) != dstHeight() || (vx_uint32)(map.cols) != dstWidth())
|
||||
throw WrapperError(std::string(__func__) + "(): x mapping size is wrong");
|
||||
|
||||
for (vx_uint32 y = 0; y < dstHeight(); y++)
|
||||
{
|
||||
const vx_float32* map_line = map.ptr<vx_float32>(y);
|
||||
for (vx_uint32 x = 0; x < 2*dstWidth(); x+=2)
|
||||
setMapping(x, y, map_line[x], map_line[x+1]);
|
||||
}
|
||||
}
|
||||
|
||||
void getMappings(cv::Mat& map_x, cv::Mat& map_y) const
|
||||
{
|
||||
if (map_x.type() != enumToCVType(srcCoordType()) || map_y.type() != enumToCVType(srcCoordType()))
|
||||
throw WrapperError(std::string(__func__) + "(): mapping type is wrong");
|
||||
if (((vx_uint32)(map_x.rows) != dstHeight() || (vx_uint32)(map_x.cols) != dstWidth()) && !map_x.empty())
|
||||
throw WrapperError(std::string(__func__) + "(): x mapping size is wrong");
|
||||
if (((vx_uint32)(map_y.rows) != dstHeight() || (vx_uint32)(map_y.cols) != dstWidth()) && !map_y.empty())
|
||||
throw WrapperError(std::string(__func__) + "(): y mapping size is wrong");
|
||||
|
||||
if (map_x.empty())
|
||||
map_x = cv::Mat((int)dstHeight(), (int)dstWidth(), enumToCVType(srcCoordType()));
|
||||
if (map_y.empty())
|
||||
map_y = cv::Mat((int)dstHeight(), (int)dstWidth(), enumToCVType(srcCoordType()));
|
||||
|
||||
for (vx_uint32 y = 0; y < dstHeight(); y++)
|
||||
{
|
||||
vx_float32* map_x_line = map_x.ptr<vx_float32>(y);
|
||||
vx_float32* map_y_line = map_y.ptr<vx_float32>(y);
|
||||
for (vx_uint32 x = 0; x < dstWidth(); x++)
|
||||
getMapping(x, y, map_x_line[x], map_y_line[x]);
|
||||
}
|
||||
}
|
||||
|
||||
void getMappings(cv::Mat& map) const
|
||||
{
|
||||
if (map.depth() != CV_MAT_DEPTH(enumToCVType(srcCoordType())) || map.channels() != 2)
|
||||
throw WrapperError(std::string(__func__) + "(): mapping type is wrong");
|
||||
if (((vx_uint32)(map.rows) != dstHeight() || (vx_uint32)(map.cols) != dstWidth()) && !map.empty())
|
||||
throw WrapperError(std::string(__func__) + "(): x mapping size is wrong");
|
||||
|
||||
if (map.empty())
|
||||
map = cv::Mat((int)dstHeight(), (int)dstWidth(), CV_MAKETYPE(CV_MAT_DEPTH(enumToCVType(srcCoordType())),2));
|
||||
|
||||
for (vx_uint32 y = 0; y < dstHeight(); y++)
|
||||
{
|
||||
vx_float32* map_line = map.ptr<vx_float32>(y);
|
||||
for (vx_uint32 x = 0; x < 2*dstWidth(); x+=2)
|
||||
getMapping(x, y, map_line[x], map_line[x+1]);
|
||||
}
|
||||
}
|
||||
#endif //IVX_USE_OPENCV
|
||||
};
|
||||
|
||||
/// Standard nodes
|
||||
namespace nodes {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user