I am trying to send image data across rosnodes and I want to get the dwImageCPU and send a pointer the data in ROS stream
by using CameraGMSL as base sample and building other things on top of it like this:
In OnInitialize()
//------------------------------------------------------------------------------
// initializes streamer
// -----------------------------------------
{
dwImageProperties cpuImageProperties{};
cpuImageProperties.width = m_cameraProperties.resolution.x;
cpuImageProperties.height = m_cameraProperties.resolution.y;
cpuImageProperties.format = DW_IMAGE_FORMAT_RGBA_UINT8;
cpuImageProperties.type = DW_IMAGE_CUDA;
cpuImageProperties.memoryLayout = DW_IMAGE_MEMORY_TYPE_DEFAULT;
CHECK_DW_ERROR(
dwImageStreamer_initialize(&m_streamerCUDAtoCPU, &cpuImageProperties, DW_IMAGE_CPU, m_sdk_context));
}
In Render():
dwImageHandle_t frameCUDA;
CHECK_DW_ERROR(dwSensorCamera_getImage(&frameCUDA, DW_CAMERA_OUTPUT_CUDA_RGBA_UINT8, frame));
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//--------------- Get a processed CUDA image from camera ---------------
// stream that image to the CPU domain
CHECK_DW_ERROR(dwImageStreamer_producerSend(frameCUDA, m_streamerCUDAtoCPU));
// receive the streamed image as a handle
dwImageHandle_t frameROS;
CHECK_DW_ERROR(dwImageStreamer_consumerReceive(&frameROS, timeout, m_streamerCUDAtoCPU));
dwImageCPU *img_raw;
CHECK_DW_ERROR(dwImage_getCPU(&img_raw, frameROS)); // Getting the image from the CPUImageHandle
auto image_CPU = img_raw->data;
// Header for image
m_img.header.stamp = ros::Time::now();
m_img.header.frame_id = "gmsl_cam";
m_img.header.seq = getFrameIndex();
// using FillImage
sensor_msgs::fillImage(m_img, sensor_msgs::image_encodings::RGBA8, img_raw->prop.height, img_raw->prop.width,
img_raw->prop.width * 4, img_raw->data);
m_img_pub.publish(m_img);
Reference to fillImage: sensor_msgs/Image Documentation
And when I visualize image feed on image_view, it is something like this : https://navistarinc-my.sharepoint.com/:i:/r/personal/atul_ahirrao_navistar_com/Documents/dwCPU_screenshot_17.12.2019.png?csf=1&e=pdcb50
I am unable to pinpoint out the exact problem with this method but I read somewhere that I should be using cudaMemcpy().
Can you please guide me what would be the arguments for this function? I have no clue about CUDA programming for that matter.