| 152 | } |
| 153 | |
| 154 | void image_pose_callback(const sensor_msgs::ImageConstPtr& image_input, |
| 155 | const geometry_msgs::TransformStampedConstPtr& pose_input) { |
| 156 | // time diff |
| 157 | double time_diff = fabs(image_input->header.stamp.toSec() - pose_input->header.stamp.toSec()) * 1000.0; |
| 158 | printf("time diff is %lf ms.\n", time_diff); |
| 159 | |
| 160 | // pose |
| 161 | Matrix4d Pose_receive = Matrix4d::Identity(); |
| 162 | |
| 163 | // using vicon |
| 164 | // Eigen::Vector3d request_position; |
| 165 | // Eigen::Quaterniond request_pose; |
| 166 | // request_position.x() = pose_input->transform.translation.x; |
| 167 | // request_position.y() = pose_input->transform.translation.y; |
| 168 | // request_position.z() = pose_input->transform.translation.z; |
| 169 | // request_pose.x() = pose_input->transform.rotation.x; |
| 170 | // request_pose.y() = pose_input->transform.rotation.y; |
| 171 | // request_pose.z() = pose_input->transform.rotation.z; |
| 172 | // request_pose.w() = pose_input->transform.rotation.w; |
| 173 | // Pose_receive.block<3,3>(0,0) = request_pose.toRotationMatrix(); |
| 174 | // Pose_receive(0,3) = request_position(0); |
| 175 | // Pose_receive(1,3) = request_position(1); |
| 176 | // Pose_receive(2,3) = request_position(2); |
| 177 | |
| 178 | // using ground truth |
| 179 | double image_time = image_input->header.stamp.toSec(); |
| 180 | double min_time_diff = 999.9; |
| 181 | int min_time_index = 0; |
| 182 | for (int i = 1; i < gt_pose_vect.size(); i++) { |
| 183 | double time_diff = fabs(image_time - gt_pose_vect[i].time); |
| 184 | if (time_diff < min_time_diff) { |
| 185 | min_time_diff = time_diff; |
| 186 | min_time_index = i; |
| 187 | } |
| 188 | } |
| 189 | printf("min time diff index %d, with diff time %lf ms.\n", min_time_index, min_time_diff * 1000.0f); |
| 190 | Pose_receive = gt_pose_vect[min_time_index].pose; |
| 191 | |
| 192 | // convert to body pose |
| 193 | // Matrix4d body_pose = Pose_receive * vicon2body.inverse(); |
| 194 | Matrix4d body_pose = Pose_receive; |
| 195 | |
| 196 | // convert to cam pose |
| 197 | cam2world = body_pose * cam02body * vicon2leica; |
| 198 | |
| 199 | receive_stamp = pose_input->header.stamp; |
| 200 | |
| 201 | // image |
| 202 | cv_bridge::CvImageConstPtr cv_img_ptr = |
| 203 | cv_bridge::toCvShare(image_input, sensor_msgs::image_encodings::MONO8); |
| 204 | cv::Mat img_8uC1 = cv_img_ptr->image; |
| 205 | undistorted_image.create(height, width, CV_8UC1); |
| 206 | if (is_distorted) { |
| 207 | cv::remap(img_8uC1, undistorted_image, undist_map1, undist_map2, CV_INTER_LINEAR); |
| 208 | } else |
| 209 | undistorted_image = img_8uC1; |
| 210 | |
| 211 | render_currentpose(); |
nothing calls this directly
no test coverage detected