Ask Your Question

Revision history [back]

You are reading a JPG image, therefore you get a BGR image in depth_map, not a float. You should use cv::Vec3b instead of cv::Vec3f to access pixels.

You could check the type of your image with depth_map.type() but it returns a number (check with CV_32FC3 if you want to use cv::Vec3f or CV_8UC3 to check with cv::Vec3b).

By the way, to avoid multiple access to the pixel, prefer doing:

cv::Vec3b pixel = depth_map.at< cv::Vec3b >( y, x );
point[ 0 ] = pixel[ 0 ]; point[ 1 ] = pixel[ 1 ]; point[ 2 ] = pixel[ 2 ];
// OR should work but untested: 
point = cv::Point3f( pixel );

You are reading a JPG image, therefore you get a BGR image in depth_map, not a float. You should use cv::Vec3b instead of cv::Vec3f to access pixels.

You could check the type of your image with depth_map.type() but it returns a number (check with CV_32FC3 if you want to use cv::Vec3f or CV_8UC3 to check with cv::Vec3b).

--EDIT code according to @stillNovice remark--

By the way, to avoid multiple access to the pixel, prefer doing:

cv::Vec3b pixel = depth_map.at< cv::Vec3b >( y, x );
point[ 0 ] point.x = pixel[ 0 ]; point[ 1 ] point.y = pixel[ 1 ]; point[ 2 ] point.z = pixel[ 2 ];
// OR should work but untested: 
point = cv::Point3f( pixel );