| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file ProjectionFactorRollingShutter.cpp | 
					
						
							|  |  |  |  * @brief Basic projection factor for rolling shutter cameras | 
					
						
							|  |  |  |  * @author Yotam Stern | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam_unstable/slam/ProjectionFactorRollingShutter.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Vector ProjectionFactorRollingShutter::evaluateError( | 
					
						
							|  |  |  |     const Pose3& pose_a, const Pose3& pose_b, const Point3& point, | 
					
						
							| 
									
										
										
										
											2023-01-10 06:52:56 +08:00
										 |  |  |     OptionalMatrixType H1, OptionalMatrixType H2, | 
					
						
							|  |  |  |     OptionalMatrixType H3) const { | 
					
						
							| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  |   try { | 
					
						
							|  |  |  |     Pose3 pose = interpolate<Pose3>(pose_a, pose_b, alpha_, H1, H2); | 
					
						
							|  |  |  |     gtsam::Matrix Hprj; | 
					
						
							|  |  |  |     if (body_P_sensor_) { | 
					
						
							|  |  |  |       if (H1 || H2 || H3) { | 
					
						
							|  |  |  |         gtsam::Matrix HbodySensor; | 
					
						
							|  |  |  |         PinholeCamera<Cal3_S2> camera( | 
					
						
							|  |  |  |             pose.compose(*body_P_sensor_, HbodySensor), *K_); | 
					
						
							| 
									
										
										
										
											2023-01-13 06:02:31 +08:00
										 |  |  |         Point2 reprojectionError(camera.project(point, Hprj, H3, {}) - | 
					
						
							| 
									
										
										
										
											2021-08-29 05:36:14 +08:00
										 |  |  |                                  measured_); | 
					
						
							|  |  |  |         if (H1) *H1 = Hprj * HbodySensor * (*H1); | 
					
						
							|  |  |  |         if (H2) *H2 = Hprj * HbodySensor * (*H2); | 
					
						
							| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  |         return reprojectionError; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         PinholeCamera<Cal3_S2> camera(pose.compose(*body_P_sensor_), *K_); | 
					
						
							|  |  |  |         return camera.project(point) - measured_; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       PinholeCamera<Cal3_S2> camera(pose, *K_); | 
					
						
							| 
									
										
										
										
											2023-01-13 06:02:31 +08:00
										 |  |  |       Point2 reprojectionError(camera.project(point, Hprj, H3, {}) - | 
					
						
							| 
									
										
										
										
											2021-08-29 05:36:14 +08:00
										 |  |  |                                measured_); | 
					
						
							|  |  |  |       if (H1) *H1 = Hprj * (*H1); | 
					
						
							|  |  |  |       if (H2) *H2 = Hprj * (*H2); | 
					
						
							| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  |       return reprojectionError; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } catch (CheiralityException& e) { | 
					
						
							| 
									
										
										
										
											2021-08-29 05:36:14 +08:00
										 |  |  |     if (H1) *H1 = Matrix::Zero(2, 6); | 
					
						
							|  |  |  |     if (H2) *H2 = Matrix::Zero(2, 6); | 
					
						
							|  |  |  |     if (H3) *H3 = Matrix::Zero(2, 3); | 
					
						
							| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  |     if (verboseCheirality_) | 
					
						
							|  |  |  |       std::cout << e.what() << ": Landmark " | 
					
						
							| 
									
										
										
										
											2022-12-23 06:25:48 +08:00
										 |  |  |                 << DefaultKeyFormatter(this->key<2>()) << " moved behind camera " | 
					
						
							|  |  |  |                 << DefaultKeyFormatter(this->key<1>()) << std::endl; | 
					
						
							|  |  |  |     if (throwCheirality_) throw CheiralityException(this->key<2>()); | 
					
						
							| 
									
										
										
										
											2021-08-14 09:42:09 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   return Vector2::Constant(2.0 * K_->fx()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 05:36:14 +08:00
										 |  |  | }  // namespace gtsam
 |