| 212 | } |
| 213 | |
| 214 | void render_currentpose() { |
| 215 | solve_pnp(); |
| 216 | |
| 217 | double this_time = ros::Time::now().toSec(); |
| 218 | |
| 219 | Matrix4d cam_pose = cam2world.inverse(); |
| 220 | |
| 221 | depthrender.render_pose(cam_pose, depth_hostptr); |
| 222 | |
| 223 | depth_mat = cv::Mat::zeros(height, width, CV_32FC1); |
| 224 | double min = 0.5; |
| 225 | double max = 1.0f; |
| 226 | for (int i = 0; i < height; i++) |
| 227 | for (int j = 0; j < width; j++) { |
| 228 | float depth = (float)depth_hostptr[i * width + j] / 1000.0f; |
| 229 | depth = depth < 500.0f ? depth : 0; |
| 230 | max = depth > max ? depth : max; |
| 231 | depth_mat.at<float>(i, j) = depth; |
| 232 | } |
| 233 | ROS_INFO("render cost %lf ms.", (ros::Time::now().toSec() - this_time) * 1000.0f); |
| 234 | printf("max_depth %lf.\n", max); |
| 235 | |
| 236 | cv_bridge::CvImage out_msg; |
| 237 | out_msg.header.stamp = receive_stamp; |
| 238 | out_msg.encoding = sensor_msgs::image_encodings::TYPE_32FC1; |
| 239 | out_msg.image = depth_mat.clone(); |
| 240 | pub_depth.publish(out_msg.toImageMsg()); |
| 241 | |
| 242 | cv::Mat adjMap; |
| 243 | depth_mat.convertTo(adjMap, CV_8UC1, 255 / (max - min), -min); |
| 244 | cv::Mat falseColorsMap; |
| 245 | cv::applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_RAINBOW); |
| 246 | cv::Mat bgr_image; |
| 247 | cv::cvtColor(undistorted_image, bgr_image, cv::COLOR_GRAY2BGR); |
| 248 | cv::addWeighted(bgr_image, 0.2, falseColorsMap, 0.8, 0.0, falseColorsMap); |
| 249 | cv_bridge::CvImage cv_image_colored; |
| 250 | cv_image_colored.header.frame_id = "depthmap"; |
| 251 | cv_image_colored.encoding = sensor_msgs::image_encodings::BGR8; |
| 252 | cv_image_colored.image = falseColorsMap; |
| 253 | pub_color.publish(cv_image_colored.toImageMsg()); |
| 254 | |
| 255 | cv::imshow("bluefox_image", bgr_image); |
| 256 | cv::imshow("depth_image", adjMap); |
| 257 | } |
| 258 | |
| 259 | int main(int argc, char** argv) { |
| 260 | ros::init(argc, argv, "cloud_banchmark"); |
no test coverage detected