Vx_array access feature_tracker demo

Dear community,

I am having some troubles in reading the values of a vx_array in a VW example. Here follows a piece of code I am using.

vx_size numItems;
vx_size stride = sizeof(vx_size);
void *base = NULL;
vxQueryArray(new_points, VX_ARRAY_ATTRIBUTE_NUMITEMS, &numItems, stride);
vxAccessArrayRange(new_points, 0, numItems, &stride, &base, VX_READ_ONLY);
vx_keypoint_t *points = (vx_keypoint_t*)base;
std::cout << points[0].x << std::endl;

Basically I have to read the values of some coordinates stored in the array “new_points”, but when I do that I get values like the ones shown in the following image:

https://imgur.com/pMHolr0

I feel like if the conversion from the “pointer to a pointer” to “vx_keypoint_t” is doing some weird cast. Do you have any idea how to get proper values out of that?
The array “should” contain some keypoints which represents the features points obtained through the feature_tracker demo, so I expect those to have some x,y coordinates.

Thanks a lot for your time!

Regards,

Alessandro

P.S. the output I get is somehow varying, like a moving feature should be, so I expect those numbers to be somehow correlated with the coordinates I am looking for

Hi,

Have you assigned a value to numItems?
From the source code in comment #1, numItems is not assigned and may cause error when querying the Array mapping.

Thanks.

I fixed it! Thank you very much :)

Hi,
I am facing the same issue, can you share the solution as i am initializing numItems as well but still the same result.

Hi, ammar.zafar8

Could you share your implementation so that we can check it for you?
Thanks.

Hello, I am trying to do the same thing but I’m not getting sensible values. Here is my code.

const vx_array fVx = this->getFeaturesArray();

std::vector<cv::Point2f> fPts;
vx_size numItems = 0;
vxQueryArray(fVx, VX_ARRAY_ATTRIBUTE_NUMITEMS, &numItems, sizeof(numItems));
vx_size stride = sizeof(vx_size);
void *base = NULL;
vxAccessArrayRange(fVx, 0, numItems, &stride, &base, VX_READ_ONLY);

for (vx_size i = 0; i < numItems; i++)
{
    vx_keypoint_t* points = (vx_keypoint_t*)base;
    vx_float32 error = points[i].error;
    vx_float32 orientation = points[i].orientation;
    vx_float32 scale = points[i].scale;
    vx_float32 strength = points[i].strength;
    vx_int32 trackingStatus = points[i].tracking_status;
    vx_int32 x = points[i].x;
    vx_int32 y = points[i].y;

    std::cout << "index: " << i << std::endl
              << ":: error:          " << error << std::endl
              << ":: orientation:    " << orientation << std::endl
              << ":: scale:          " << scale << std::endl
              << ":: strength:       " << strength << std::endl
              << ":: trackingStatus: " << trackingStatus << std::endl
              << ":: x:              " << x << std::endl
              << ":: y:              " << y << std::endl;
    fPts.push_back(cv::Point2f(x, y));
}

And the output.

index: 0
:: error:          105.787
:: orientation:    88.9296
:: scale:          139.949
:: strength:       68.8853
:: trackingStatus: 1125120208
:: x:              1116985521
:: y:              1123146744
index: 1
:: error:          161.016
:: orientation:    157.93
:: scale:          119.941
:: strength:       142.944
:: trackingStatus: 1124273989
:: x:              1125120000
:: y:              1121681061
...

Found a solution in case anyone else is struggling with this. In my case, the problem was I was not defining the arrays to be of type NVX_TYPE_KEYPOINTF when creating the arrays.

vx_size numCorners = 0;
vx_size numTracking = 0;

vx_array previousKeypoints = this->getPrevFeaturesArray();
vx_array currentKeypoints = this->getFeaturesArray();


ERROR_CHECK_OBJECT(currentKeypoints);
ERROR_CHECK_OBJECT(previousKeypoints);
ERROR_CHECK_STATUS(vxQueryArray(previousKeypoints, VX_ARRAY_NUMITEMS, &numCorners, sizeof(numCorners)));

if (numCorners > 0)
{
    vx_size oldStride;
    vx_size newStride;
    vx_map_id oldMap;
    vx_map_id newMap;
    vx_uint8* oldBuff;
    vx_uint8* newBuff;

    ERROR_CHECK_STATUS(vxMapArrayRange(previousKeypoints, 0, numCorners, &oldMap,
                                       &oldStride, (void **)&oldBuff,
                                       VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0 ) );
    ERROR_CHECK_STATUS(vxMapArrayRange(currentKeypoints, 0, numCorners, &newMap,
                                       &newStride, (void **) &newBuff,
                                       VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0));

    for (vx_size i = 0; i < numCorners; i++)
    {
        nvx_keypointf_t* kpOld = (nvx_keypointf_t*)(oldBuff + i * oldStride);
        nvx_keypointf_t* kpNew = (nvx_keypointf_t*)(newBuff + i * newStride);
        if (kpNew->tracking_status)
        {
            fPrev.push_back(cv::Point2f(kpOld->x, kpOld->y));
            f.push_back(cv::Point2f(kpNew->x, kpNew->y));
        }
    }
    ERROR_CHECK_STATUS(vxUnmapArrayRange(previousKeypoints, oldMap));
    ERROR_CHECK_STATUS(vxUnmapArrayRange(currentKeypoints, newMap));
}

Thanks for updating your status.