Conversion Camera Capture to ROS

Hi everyone.

I’m trying to send to RVIZ the image captured from jetson-inference.
The problem is the format of the image.

RVIZ support RGB8 and the image who provide from the jetson-inference library offer FLOAT32 with 4 channels image.

I’m trying to use this code:

cv::Mat image = cv::Mat(camera->GetWidth(),camera->GetHeight(),CV_32FC4, imgRGBA);

cv::Mat imgrgb;
cv::cvtColor(image,imgrgb, cv::COLOR_RGBA2BGR);
header.seq =  count; // user defined counter
header.stamp = ros::Time::now(); // time

img_bridge = cv_bridge::CvImage(header, sensor_msgs::image_encodings::BGR8, imgrgb);


img_bridge.toImageMsg(img_msg); // from cv_bridge to sensor_msgs::Image

Best Regards

Gabriel

Solution:
while (n.ok() && !signal_recieved )
{
float* imgRGBA = NULL;
void* imgCPU = NULL;
void* imgCUDA = NULL;
float* imgRGBAX = NULL;

	if (!camera->Capture(&imgCPU,&imgCUDA,1000))
		printf("\nCamera Failed\n");
	if (!camera->ConvertRGBA(imgCUDA,&imgRGBA,true)) {
		printf("Failed to convert image/n");
		}
		
	detectNet::Detection* detections = NULL;

	const int numDetections = net->Detect(imgRGBA, camera->GetWidth(), camera->GetHeight(), &detections);
    counter = counter+1;	

	printf(" %f \n",counter);
	cv::Mat im=cv::Mat(mHeight,mWidth,CV_32FC4, imgRGBA);

	if (counter>=5)
	{
		counter=0;
		cv_bridge::CvImage img_bridge;

		std_msgs::Header header;
		header.seq=counter;
		header.stamp = ros::Time::now();
		img_bridge = cv_bridge::CvImage(header,sensor_msgs::image_encodings::RGBA8,im);
		img_bridge.toImageMsg(img_msg);
		pub.publish(img_msg);		
    }
}
SAFE_DELETE(camera);

Cool! Thanks for sharing!