vxCreateArray doesn't allocated entries

Hello,

I’m unable to create and fill in arrays for the nvxuFindHomography() call. the
vxQueryArray(srcPoints, VX_ARRAY_ATTRIBUTE_NUMITEMS, &num_items, sizeof(num_items));
is returning 0 and the vxAccessArrayRange() call is returning
[NVX LOG] vxAccessArrayRange: invalid range

Here’s the code:

vx_size capacity = 4;
    vx_array srcPoints = vxCreateArray (*context_, VX_TYPE_KEYPOINT, capacity);
    NVXIO_CHECK_REFERENCE(srcPoints);
    vx_array dstPoints = vxCreateArray (*context_, VX_TYPE_KEYPOINT, capacity);
    NVXIO_CHECK_REFERENCE(dstPoints);  
    vx_array inliers   = vxCreateArray (*context_, VX_TYPE_UINT8, capacity);
    NVXIO_CHECK_REFERENCE(inliers);

    vx_status status = vxGetStatus((vx_reference)srcPoints);
    if (status != VX_SUCCESS)
        printf ("failed to create srcPoints %d\n", status);

    printf ("created arrays with capacity %d\n", (int) capacity);

    vx_size stride = 0; //sizeof(vx_keypoint_t);
    void *base = NULL;

    vx_size num_items = 0;
    vxQueryArray(srcPoints, VX_ARRAY_ATTRIBUTE_NUMITEMS, &num_items, sizeof(num_items));
    printf ("accessing src Points %d\n", (int)num_items);

    // fill in source points
    NVXIO_SAFE_CALL(vxAccessArrayRange(srcPoints, 0, 3, &stride, &base, VX_READ_AND_WRITE));

    for (int idx = 0; idx < 3; idx++)
    {
        vxArrayItem(vx_keypoint_t, base, idx, stride).x = src_points[idx*2];
        vxArrayItem(vx_keypoint_t, base, idx, stride).y = src_points[idx*2 + 1];
    }
    vxCommitArrayRange(srcPoints, 0, 3, base);
        
    // fill in dst points
    stride = 0;sizeof(vx_keypoint_t);
    base = NULL;
    vxAccessArrayRange(dstPoints, 0, 3, &stride, &base, VX_READ_AND_WRITE);
    printf ("accessing dst Points\n");
    for (int idx = 0; idx < 4; idx++)
    {
        vxArrayItem(vx_keypoint_t, base, idx, stride).x = dst_points[idx*2];
        vxArrayItem(vx_keypoint_t, base, idx, stride).y = dst_points[idx*2 + 1];
    }
    vxCommitArrayRange(srcPoints, 0, 3, base);

    printf ("finding homography\n");

    nvxuFindHomography (*context_, srcPoints, dstPoints,
                        hmatrix, NVX_FIND_HOMOGRAPHY_METHOD_USE_ALL_POINTS, 
                        3, 2000, 10, 0.995, 0.45, inliers);

output:

created arrays with capacity 4
accessing src Points 0
[NVX LOG] vxAccessArrayRange: invalid range : {0, 3}

Thanks!

I should mention, that in this example I pushed around a pointer to context_. But I have also tried the non-pointer approach that is shown in the VisionWorks examples. The result is the same.

Hi Visionear,

vxAccessArrayRange/vxCommitArrayRange functions are used to access a set of valid items in the array.

When you create the array with a given capacity, you tell how much memory needs to be allocated, but the array is empty (there is no item in it yet). Then, calling vxAccessArrayRange returns an error.

You need to add items first and then only, you can call vxAccessArrayRange if needed.

(Note that nvxuFindHomography supports also other keypoint structures with float coordinates: NVX_TYPE_POINT2F & NVX_TYPE_KEYPOINTF).

I would suggest you try something like this by using vxAddArrayItems:

vx_size capacity = 4;
        vx_array srcPoints = vxCreateArray (*context_, VX_TYPE_KEYPOINT, capacity);
        NVXIO_CHECK_REFERENCE(srcPoints);
        vx_array dstPoints = vxCreateArray (*context_, VX_TYPE_KEYPOINT, capacity);
        NVXIO_CHECK_REFERENCE(dstPoints); 
        vx_array inliers   = vxCreateArray (*context_, VX_TYPE_UINT8, capacity);
        NVXIO_CHECK_REFERENCE(inliers);

        vx_status status = vxGetStatus((vx_reference)srcPoints);
        if (status != VX_SUCCESS)
            printf ("failed to create srcPoints %d\n", status);

        printf ("created arrays with capacity %d\n", (int) capacity);

        vx_keypoint_t src_keypoints[3], dst_keypoints[3];
        for (int idx = 0; idx < 3; idx++)
        {
            src_keypoints[idx].x = src_points[idx*2];
            src_keypoints[idx].y = src_points[idx*2 + 1];
            dst_keypoints[idx].x = dst_points[idx*2];
            dst_keypoints[idx].y = dst_points[idx*2 + 1];
        }
        status = vxAddArrayItems ( srcPoints, 3, &src_keypoints, sizeof(vx_keypoint_t));
        if (status != VX_SUCCESS)
            printf ("failed to add items to srcPoints %d\n", status);
        status = vxAddArrayItems ( dstPoints, 3, &dst_keypoints, sizeof(vx_keypoint_t));
        if (status != VX_SUCCESS)
            printf ("failed to add items to dstPoints %d\n", status);
         
        printf ("finding homography\n");

        nvxuFindHomography (*context_, srcPoints, dstPoints,
                            hmatrix, NVX_FIND_HOMOGRAPHY_METHOD_USE_ALL_POINTS,
                            3, 2000, 10, 0.995, 0.45, inliers);