Ask Your Question
0

Accessing pixel intensity values 16 unsigned char

asked 2016-09-16 16:33:36 -0600

skr_robo gravatar image

I have the following reference: Link

to access the pixel intensity values of an image. This image is being converted from ROS to OpenCV and can be converted to two different formats: 32 bit float and 16 bit unsigned char. This is a depth image coming out of zed camera and hence uses single channel. I am working with C++ and the code is running as a ROS node. The above link has the following line:

Scalar intensity = img.at<uchar>(y, x);

I have two questions: 1) For 32FC1 format, I tried replacing uchar with float and it worked. Is this the right way to do it or is there a better option? 2) I am not able to find the uchar counterpart for 16 bit unsigned char (16UC1). I tried using uchar itself, but it is giving me mostly zeros and I am pretty convinced that it is not right. Any help would be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-16 20:58:31 -0600

Guyygarty gravatar image

I don't use floats but that seems like the right way to me. For 16 bit I use at<unsigned __int16>(y,x) or at<__int16>(y, x).

guy

edit flag offensive delete link more

Comments

well, ushort would be ... shorter :)

berak gravatar imageberak ( 2016-09-16 22:42:21 -0600 )edit

I tried unsigned __int16 and __int16. But that threw the error: template argument 1 is invalid during catkin_make (The catkin workspace is being used for ROS). The ushort worked, but it rounded off the depth values to nearest integer (Instead of seeing values like 1.234, 3.456 etc, I was seeing 1.000 and 3.000)

skr_robo gravatar imageskr_robo ( 2016-09-20 22:43:53 -0600 )edit

wait, for float images you need float access, for unsigned short, ushort.

berak gravatar imageberak ( 2016-09-21 00:21:22 -0600 )edit

Note that it is not unsigned int, it is 16 bit unsigned char.

skr_robo gravatar imageskr_robo ( 2016-09-26 12:49:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-16 16:33:36 -0600

Seen: 2,835 times

Last updated: Sep 16 '16