Need help to convert nvxcu_pitch_linear_image_t image to vx_image

Hi,

I have created nvxcu_pitch_linear_image_t image using the following function:

nvxcu_pitch_linear_image_t createImage(uint32_t width, uint32_t height, nvxcu_df_image_e format)
{
NVXIO_ASSERT(format == NVXCU_DF_IMAGE_U8 ||
format == NVXCU_DF_IMAGE_RGB ||
format == NVXCU_DF_IMAGE_RGBX);

nvxcu_pitch_linear_image_t image = { };

image.base.format = format;    
image.base.image_type = NVXCU_PITCH_LINEAR_IMAGE;
image.base.width = width;
image.base.height = height;

size_t pitch = 0ul;
uint32_t cn = format == NVXCU_DF_IMAGE_U8 ? 1u :
              format == NVXCU_DF_IMAGE_RGB ? 3u : 4u;

NVXIO_CUDA_SAFE_CALL( cudaMallocPitch(&image.planes[0].dev_ptr, &pitch,
                      image.base.width * cn, image.base.height) );
image.planes[0].pitch_in_bytes = static_cast<uint32_t>(pitch);

return image;

}

The image is of type NVXCU_DF_IMAGE_RGBX. I want to convert it to vx_image. I have written the following code to convert nvxcu_pitch_linear_image_t to vx_image.

               vx_imagepatch_addressing_t src_addr;
               src_addr.dim_x = eventData.frame.base.width;
               cout<<"Height : "<<src_addr.dim_x<<endl;
               cout<<"Height : "<<eventData.frame.base.width<<endl;
               src_addr.dim_y = eventData.frame.base.height;
               src_addr.stride_x = 4*sizeof( vx_uint8 );
               src_addr.stride_y = eventData.frame.planes[0].pitch_in_bytes;
               /*src_addr.scale_x = VX_SCALE_UNITY;
               src_addr.scale_x = VX_SCALE_UNITY;
               src_addr.step_x = 1;
               src_addr.step_y = 1;*/
               void *src_ptrs[] = { eventData.frame.planes[0].dev_ptr };                                     
               vx_image img1 = vxCreateImageFromHandle( context, VX_DF_IMAGE_RGBX, &src_addr,
                                        //(void **)&eventData.frame.planes[0].dev_ptr, VX_MEMORY_TYPE_HOST );
                                        src_ptrs, VX_MEMORY_TYPE_HOST );

               renderer1->putImage(img1);

But when I am rendereing the vx_image I am getting a black screen.

Please suggest what I am doing wrong.

Hi,

Please correct me if I misunderstood your implementation.
nvxcu_pitch_linear_image_t is a GPU memory but your create a CPU based vx_image without memory copy.

You may need a cudaMemcpy() to transfer data back to CPU.
Or create a vx_image directly on the GPU memory.

render_->putImage(ovxio::image_t(image, VX_READ_ONLY, NVX_MEMORY_TYPE_CUDA));

Thanks.

render_->putImage(ovxio::image_t(image, VX_READ_ONLY, NVX_MEMORY_TYPE_CUDA));

That’s in interesting answer. It looks to me like image_t() is a simple constructor. It returns an image_t structure and accepts a vx_image as an argument.

ovxio.

image_t::image_t(vx_image image, vx_enum usage, vx_enum mem_type) :
nvidiaio::image_t(),
// OpenVX
image_ (image),
addrs_ { },
ptrs_ { },
map_ids_ { }

The question being asked here, and by myself is that I have a variable of type
nvxcu_pitch_linear_image and I would like to turn it in to a vx_image.