8 #include <opencv2/highgui/highgui.hpp>
21 :
geo::RenderResult(z_buffer.cols, z_buffer.rows), z_buffer_(z_buffer), pixels_(pixels)
27 float old_depth = z_buffer_.at<
float>(y, x);
30 z_buffer_.at<
float>(y, x) = depth;
31 pixels_.push_back(y * z_buffer_.cols + x);
33 else if (depth < old_depth)
35 z_buffer_.at<
float>(y, x) = depth;
56 unsigned int width = view.
getWidth();
63 cv::Mat sensor_depth_img(height, width, CV_32FC1, 0.0);
64 for (uint y = 0; y < height; ++y)
65 for (uint x = 0; x < width; ++x)
66 sensor_depth_img.at<
float>(y, x) = view.
getDepth(x, y);
68 double min_error = 1e9;
70 for(
double droll = -0.0; droll <= 0.0; droll += 0.005)
72 for(
double dpitch = -0.0; dpitch <= 0.0; dpitch += 0.005)
75 m.
setRPY(droll, dpitch, 0);
78 test_pose.
t = sensor_pose.
t;
79 test_pose.
R = m * sensor_pose.
R;
81 for(
double dz = -0.05; dz < 0.05; dz += 0.005)
83 test_pose.
t.
z = sensor_pose.
t.
z + dz;
86 cv::Mat model(height, width, CV_32FC1, 0.0);
87 SampleRenderResult res(model, pixels);
90 rasterizer.
render(opt, res);
96 double total_error = 0;
99 unsigned int p_idx = *it;
101 float ds = sensor_depth_img.at<
float>(p_idx);
105 float dm = model.at<
float>(p_idx);
106 float diff = std::abs(dm - ds);
119 double avg_error = total_error / n;
120 if (avg_error < min_error)
122 min_error = avg_error;
123 updated_sensor_pose = test_pose;