Milind Deore
Milind Deore

Reputation: 3063

An array to vx_image

I would like to create a vx_image out of an array. Let us say i have 2D array:

unsigned char img_array[720][1280]={{..},{..}, ... }   // filled with values

I would like to make it

vx_image

so that i can perform various pixel level operations. Any other idea to do the same thing would also be fine.

Upvotes: 1

Views: 603

Answers (2)

Benjamin Bihler
Benjamin Bihler

Reputation: 2059

You can use the method vxCreateImageFromHandle to create a vx_image from externally allocated memory: https://www.khronos.org/registry/OpenVX/specs/1.1/html/df/d09/group__group__image.html#ga5abb694617a79024621e3ba95237a109.

Upvotes: 0

Milind Deore
Milind Deore

Reputation: 3063

I think the best way to interoperate is: from VX(CUDA) to CUDA(native) OR OpenCV(CUDA) and vice-versa. One of the nice way is given here. And the other possible way is below (This snippet is taken from VisionWorks Document):

void processImageWithCUDA(vx_image src, vx_image dst)
{
    vx_df_image format = 0;
    vxQueryImage(src, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format));
    assert( format == VX_DF_IMAGE_RGB );
    // Get valid region
    vx_rectangle_t rect;
    vxGetValidRegionImage(src, &rect);
    // Map VisionWorks data objects into CUDA device memory
    vx_map_id src_map_id;
    vx_uint8* src_ptr;
    vx_imagepatch_addressing_t src_addr;
    vxMapImagePatch(src, &rect, 0, &src_map_id, &src_addr, (void **)&src_ptr, VX_READ_ONLY, NVX_MEMORY_TYPE_CUDA, 0);
    vx_map_id dst_map_id;
    vx_uint8* dst_ptr;
    vx_imagepatch_addressing_t dst_addr;
    vxMapImagePatch(dst, &rect, 0, &dst_map_id, &dst_addr, (void **)&dst_ptr, VX_WRITE_ONLY, NVX_MEMORY_TYPE_CUDA, 0);
    // Call CUDA function
    cudaStream_t stream = NULL;
    myOperations_image(src_addr.dim_x, src_addr.dim_y,
                       stream);
    cudaStreamSynchronize(stream);
    // Unmap VisionWorks data objects from CUDA device memory
    vxUnmapImagePatch(src, src_map_id);
    vxUnmapImagePatch(dst, dst_map_id);
}

In both the cases we are not copying to host memory, else it will drastically degrade performance, with a caveat that operations inside myOperations_image() should also maintain this rule.

Upvotes: 0

Related Questions