I’m trying to capture 12-bit images using Libargus and publish them to ROS. In an attempt to not lose any data, I need the images to be published as BGR16 encoding.
I’ve been following a method mentioned across the forum which is for publishing 8-bit images to ROS:
// Set the pixel format to PIXEL_FMT_YCbCr_420_888
iEGLStreamSettings->setPixelFormat(Argus::PIXEL_FMT_YCbCr_420_888);
...
// Create a buffer with NvBufferColorFormat_ABGR32
m_dmabuf = iNativeBuffer->createNvBuffer(iEglOutputStream->getResolution(), NvBufferColorFormat_ABGR32, NvBufferLayout_Pitch);
...
// Convert to cv::Mat and use cvtColor
void *pdata = NULL;
NvBufferMemMap(m_dmabuf, 0, NvBufferMem_Read, &pdata);
NvBufferMemSyncForCpu(m_dmabuf, 0, &pdata);
cv::Mat imgbuf = cv::Mat(1106, 1936, CV_8UC4, pdata);
cv::Mat display_img;
cvtColor(imgbuf, display_img, CV_RGBA2BGR);
...
// Use cv_bridge to convert the image to a ROS msg
NvBufferMemUnMap(m_dmabuf, 0, &pdata);
cv_bridge::CvImage out_msg;
out_msg.encoding = sensor_msgs::image_encodings::BGR8;
out_msg.image = display_img;
image_pub.publish(out_msg.toImageMsg());
Not surprisingly, this solution doesn’t work for 12-bit images. Each images arrives distorted (each row of pixels is further offset from the last).
Updating CV_8UC4 → CV_16UC4, and BGR8 → BGR16 does not work. The program crashes at the cvtColor function, without returning an error…
Hi @JerryChang, csi_pixel_bit_depth has been set to 12. Here is a portion of the device tree, let me know if you want more or all of it. It’s worth noting that I have successfully received images using these drivers before, even through Argus. I’ve just been struggling with the conversion from Argus → OpenCV → ROS.
Hi,
ABGR32 is 8-bit R 8-bit G 8-bit B 8-bit A for each pixel. Hardware blocks in Xavier do not support12-bit formats, so libargus cannot output 12-bit images. This use-case of sending 12-bit images from libargus to ROS is not supported due to hardware constraint.