hbVPWarpPerspective

typedef struct {
  float transformMatrix[9];
  int8_t interpolation;
  int8_t borderType;
  uint8_t borderValue;
  int8_t isInverse;
} hbVPWarpPerspectiveParam;

WarpPerspective算子参数。

  • 成员

    成员名称描述
    transformMatrix[9]WarpPerspective转换矩阵,3X3矩阵。
    interpolationWarpPerspective中的插值类型,支持 hbVPInterpolationType 中的NEAREST和LINEAR类型。
    borderType保留参数。
    borderValue保留参数。
    isInverse标志transformMatrix是否为逆矩阵,非零表示逆矩阵(src = M * dst),0表示正矩阵(dst = M * src)
int32_t hbVPWarpPerspective(hbUCPTaskHandle_t *taskHandle,
                            hbVPImage *dstImg,
                            hbVPImage const *srcImg,
                            hbVPPerspectiveParam const *perspectiveParam);

调用WarpPerspective API。

  • 参数
    • [out] taskHandle 任务句柄,负责算子与UCP架构的交互。
    • [out] dstImg 输出图像,type、format和size与输入图像一致。
    • [in] srcImg 输入图像,type支持U8C1,format支持Y和nv12。
    • [in] perspectiveParam 算子参数。
  • 返回值
    • 返回 0 则表示API成功执行,否则执行失败。
注解

透视算子在某些场景下会回退到 ref 代码分支(非优化的参考实现分支),性能下降。判断条件如下:

设 transformMatrix 为 3x3 透视矩阵,元素布局如下:

  a11 a12 xt
  a21 a22 yt
  a31 a32 zt

即 transformMatrix[0..8] 依次对应 a11, a12, xt, a21, a22, yt, a31, a32, zt。

记 dstWidth、dstHeight 为输出图像的宽和高,定义:

float32_t x_max = fabs(a11) * (dstWidth + 0.5F) +
                  fabs(a12) * (dstHeight + 0.5F) + fabs(xt) - 0.5F;
float32_t y_max = fabs(a21) * (dstWidth + 0.5F) +
                  fabs(a22) * (dstHeight + 0.5F) + fabs(yt) - 0.5F;
float32_t z_max = fabs(a31) * (dstWidth + 0.5F) +
                  fabs(a32) * (dstHeight + 0.5F) + fabs(zt) - 0.5F;

当满足下列条件时算子走优化分支:

(x_max / z_max) <= ((1 << 13) - 1) &&
(y_max / z_max) <= ((1 << 13) - 1)

否则算子内部会判定为边界条件溢出,回退到 ref 分支执行。具体实现请参考 DSP 算子源码。