Trying to publish 16 bit images as ROS msg
Hi all,
I am trying to publish sensor msg from lepton camera connected over SPI. The images that I get from the sensor is 14 bit, I have zero padded it and have it as 16 bit value. I am trying to publish the 16 bit image as sensor::msgs Image, but the the image message type can hold only 8 bit of data as the data type is uint8[] data
(I used the encoding mono16
). Then I tried with opencv Mat and cv_bridge, the relevant code is
cv::Mat image_holder(IR_img.height,IR_img.width, CV_16UC1);
for(int i=(NO_BITS_SKIP+1); i<FRAME_SIZE_UINT16;i++)
{
if(i % PACKET_SIZE_UINT16 < 2)
continue;
image_holder.at<uchar>(ii,jj)=(unsigned char)init_buf[i];
jj++;
if(jj==80)
{
jj=0;
ii++;
}
if(ii==60)
{
ii=0;
}
}
where init_buf is a 16bit pointer to the data. When i assign the values into the matrix, its ignoring the 2nd byte and considers only 1st byte. and surprisingly the size of the image is half the size.
This is the 8bit image (successfully published)
16bit image I am having problems with
I am not sure where i am going wrong. Is there a tutorial I can refer to for publishing 16 bit grayscale images? Any help is greatly appreciated..
I am using ROS indigo and opencv 2.4.8
Thanks