专栏算法工具链hbVPRoiResize参数中roi有哪些限制条件?

hbVPRoiResize参数中roi有哪些限制条件?

已解决
默认809922025-12-25
77
9

芯片型号:J6M

问题描述:使用hbVPRoiResize函数对NV12图像进行crop和resize,执行出错,代码如下:

int32_t resize_width = 1024;
int32_t resize_height = 480;
auto image_width_stride = ALIGN_32(resize_width);
int32_t data_size = image_width_stride * resize_height;
hbUCPSysMem output_mem[2];
HB_CHECK_SUCCESS(hbUCPMallocCached(&output_mem[0], data_size, 0),
"hbUCPMallocCached input_data failed");
HB_CHECK_SUCCESS(hbDSPAddrMap(&output_mem[0], &output_mem[0]),
"Failed to hbDSPAddrMap input_data");
HB_CHECK_SUCCESS(hbUCPMallocCached(&output_mem[1], data_size / 2, 0),
"hbUCPMallocCached output_mem failed");
HB_CHECK_SUCCESS(hbDSPAddrMap(&output_mem[1], &output_mem[1]),
"Failed to hbDSPAddrMap output_mem");
hbVPImage *dst = &spec.dst;
dst->imageFormat = HB_VP_IMAGE_FORMAT_NV12;
dst->imageType = HB_VP_IMAGE_TYPE_U8C1;
dst->width = resize_width;
dst->height = resize_height;
dst->stride = image_width_stride;
dst->dataVirAddr = output_mem[0].virAddr;
dst->dataPhyAddr = output_mem[0].phyAddr;
dst->uvStride = image_width_stride;
dst->uvVirAddr = output_mem[1].virAddr;
dst->uvPhyAddr = output_mem[1].phyAddr;


LOGI("resize form {} x {} to {} x {}", src->width, src->height, dst->width, dst->height);


hbUCPTaskHandle_t task{nullptr};
hbUCPSchedParam sched_param;
HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);
sched_param.backend = HB_UCP_ALL_BACKENDS;

// hbVPResize(&task, dst, src, HB_VP_INTER_LINEAR);

hbVPRoi roi{0, 648, 3839, 2159};
hbVPRoiResizeParam param{HB_VP_INTER_LINEAR, {0, 0, 0, 0}};
LOGI("roi form {} x {} to {} x {}", roi.left, roi.top, roi.right, roi.bottom);
hbVPRoiResize(&task, dst, src, &roi, &param);
HB_CHECK_SUCCESS(hbUCPSubmitTask(task, &sched_param),
"hbUCPSubmitTask failed");
HB_CHECK_SUCCESS(hbUCPWaitTaskDone(task, 0), "hbUCPWaitTaskDone failed");
HB_CHECK_SUCCESS(hbUCPReleaseTask(task), "hbUCPReleaseTask failed");
hbUCPMemFlush(&output_mem[0], HB_SYS_MEM_CACHE_INVALIDATE);
hbUCPMemFlush(&output_mem[1], HB_SYS_MEM_CACHE_INVALIDATE);

代码在J6M执行时报错如下:

 

[E][495569][12-25][11:34:46:221][test_demosaicing_op.cc:216][dsp_samples][TUTORIAL] hbUCPSubmitTask failed ,

error code: -200004

[E][495569][12-25][11:34:46:221][hb_vp_roi_resize.cpp:86][dsp_samples][VP] dstImg padding height(include top

and bottom) should be multiple of 4, given padding height: 75

[E][495569][12-25][11:34:46:221][hb_vp_roi_resize.cpp:239][dsp_samples][VP] roi scale is invalid
[E][495569][12-25][11:34:46:221][hb_ucp.cpp:74][dsp_samples][UCP] taskHandle is null pointer

请问设置roi时有哪些限制?

算法工具链
征程6
评论1
0/1000
  • Huanghui
    Lv.5
    2025-12-25
    0
    8
    • 默认80992回复Huanghui:
      感谢回复!
      原图大小为3840x2160,roi是把648行以下图像裁剪下来然后进行缩放,执行时报错,但我只要把roi从[0, 648, 3839, 2159]改为[0, 360, 3839, 2159]就可以执行成功,文档里没有描述对roi的具体限制,但有些roi确实会执行失败,不知这里是bug还是有限制没有描述出来?
      2025-12-25
      0
    • Huanghui回复默认80992:

      手到,我们先浮现分析一下,稍后同步你哈~

      2025-12-25
      0
    • YCJ回复默认80992:

      我看到了您是J6M的板子,请问一下您的工具链版本是多少?

      2025-12-25
      0
    • 默认80992回复YCJ:

      Horizon OpenExplorer 3.0.31(release_date:202501)

      2025-12-25
      0
    • YCJ回复默认80992:

      您的开发板直接跑OE包的程序 /data/horizon_j6_open_explorer_v3.0.31-py310_20241231/samples/ucp_tutorial/custom_operator/dsp_sample/dsp_code/demosaicing/demosaic_ivp.cc 有问题吗?

      2025-12-25
      0
    • 默认80992回复YCJ:

      原有代码是没问题的,上面也说了,只有有些roi的值会导致失败。

      2025-12-26
      0
    • 默认80992回复Huanghui:

      现在有什么进展吗?

      2026-01-09
      0
    • Huanghui回复默认80992:

      你好,这个问题是这样的,首先是roi区域的计算,这个区域是ROI与原始图像src的交集,其次缩放的w,h比例必须是一样的,也就是等比例缩放。这里等比例的比例计算为:计算roi区域和最终dst的区域的width和height方向的比例,选择较小比例作为缩放比例,不满足的width和height系统需要padding。需要注意的是:对于YUV,SRC / DST的height和width都需要是偶数,另外padding部分也需要满足4的倍数。处理流程概括如下:

      1. ROI 区域先取和 src 的交集(保证不越界)
      2. 必须等比例缩放:
      - 计算 sx = dst_w / roi_w
      - 计算 sy = dst_h / roi_h
      - 取 s = min(sx, sy)
      3. 另一个方向不足的部分用 padding 补齐
      4. 对于 YUV:src/dst 的 width/height 必须是偶数
      5. 还额外有:padding 的 top+bottom 或 left+right 的总 padding 需要满足 4 的倍数

      以你这里为例:

      从[ 0, 648, 3839, 2159 ]为 480 * 1024时,

      -ROI 宽 roi_w ≈ 3839 - 0 + 1 = 3840 , ROI 高 roi_h ≈ 2159 - 648 + 1 = 1512

      -1024​ / 3840 = 0.26, 480 / 1512 = 0.31, 使用0.26作为缩放比例。

      -宽会刚好贴满 1024 ,高会不够 480 , 需要 padding

      -scaled_h≈roi_h×s≈1512×0.266666...=403.2= 403

      padding_h=dst_h−scaled_h=480−scaled_h=75⇒scaled_h=405,总 padding 高度(top+bottom)= 480 - 405 = 75。

      可以 微调 ROI 的 top/bottom 。如roi{0, 644, 3839, 2159}

      2026-01-30
      0