cv::Mat load_bmp_depth( std::string filename ) { // load the image cv::Mat in_depth_map = cv::imread( filename, -1 ); // get the image channels std::vector depth_channels; cv::split( in_depth_map, depth_channels ); cv::Mat r_channel, g_channel, b_channel; depth_channels[2].convertTo( r_channel, CV_32SC1 ); depth_channels[1].convertTo( g_channel, CV_32SC1 ); depth_channels[0].convertTo( b_channel, CV_32SC1 ); // convert to a standard depth map in meters cv::Mat depth_map( in_depth_map.rows, in_depth_map.cols, CV_32FC1 ); for (int r = 0; r < depth_map.rows; ++r) for (int c = 0; c < depth_map.cols; ++c) { float val = 1e-6f * ( ( r_channel.at(r,c) << 16 ) | ( g_channel.at(r,c) << 8 ) | b_channel.at(r,c) ); depth_map.at(r,c) = val; } return depth_map; }