This section demonstrates functionality implementation of User Custom Node.
You must provide the actual implementation for the node.
1.1 Define comparison functions to use with standard qsort
algorithm:
int compare_keypoints_coord_only(const void* ptr1, const void* ptr2)
{
return (kp1->
y < kp2->
y);
return (kp1->
x < kp2->
x);
}
int compare_keypoints_with_strength(const void* ptr1, const void* ptr2)
{
return compare_keypoints_coord_only(ptr1, ptr2);
}
1.2 Define a kernel function with the following prototype:
In the kernel function we get all input and output parameters:
if (num != 3)
if (dst_capacity < num_items)
{
"[keypoint_array_sort] Destination Array is too small (required capacity = " VX_FMT_SIZE ", actual = " VX_FMT_SIZE ")",
num_items, dst_capacity);
}
1.3 Copy the data from the source array to the destination array as qsort
operates in-place:
1.4 Perform a sort operation on the destination array:
void *dst_ptr = NULL;
qsort(dst_ptr, num_items, dst_stride, &compare_keypoints_with_strength);
else
qsort(dst_ptr, num_items, dst_stride, &compare_keypoints_coord_only);
The Full Code for the Node Implementation
int compare_keypoints_coord_only(const void* ptr1, const void* ptr2)
{
return (kp1->
y < kp2->
y);
return (kp1->
x < kp2->
x);
}
int compare_keypoints_with_strength(const void* ptr1, const void* ptr2)
{
return compare_keypoints_coord_only(ptr1, ptr2);
}
{
if (num != 3)
if (dst_capacity < num_items)
{
"[keypoint_array_sort] Destination Array is too small (required capacity = " VX_FMT_SIZE ", actual = " VX_FMT_SIZE ")",
num_items, dst_capacity);
}
void *src_ptr = NULL;
void *dst_ptr = NULL;
qsort(dst_ptr, num_items, dst_stride, &compare_keypoints_with_strength);
else
qsort(dst_ptr, num_items, dst_stride, &compare_keypoints_coord_only);
}