| 2113 | } |
| 2114 | |
| 2115 | int Optimizer::OptimizeSim3(KeyFrame *pKF1, KeyFrame *pKF2, vector<MapPoint *> &vpMatches1, g2o::Sim3 &g2oS12, const float th2, |
| 2116 | const bool bFixScale, Eigen::Matrix<double,7,7> &mAcumHessian, const bool bAllPoints) |
| 2117 | { |
| 2118 | g2o::SparseOptimizer optimizer; |
| 2119 | g2o::BlockSolverX::LinearSolverType * linearSolver; |
| 2120 | |
| 2121 | linearSolver = new g2o::LinearSolverDense<g2o::BlockSolverX::PoseMatrixType>(); |
| 2122 | |
| 2123 | g2o::BlockSolverX * solver_ptr = new g2o::BlockSolverX(linearSolver); |
| 2124 | |
| 2125 | g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr); |
| 2126 | optimizer.setAlgorithm(solver); |
| 2127 | |
| 2128 | // Camera poses |
| 2129 | const Eigen::Matrix3f R1w = pKF1->GetRotation(); |
| 2130 | const Eigen::Vector3f t1w = pKF1->GetTranslation(); |
| 2131 | const Eigen::Matrix3f R2w = pKF2->GetRotation(); |
| 2132 | const Eigen::Vector3f t2w = pKF2->GetTranslation(); |
| 2133 | |
| 2134 | // Set Sim3 vertex |
| 2135 | ORB_SLAM3::VertexSim3Expmap * vSim3 = new ORB_SLAM3::VertexSim3Expmap(); |
| 2136 | vSim3->_fix_scale=bFixScale; |
| 2137 | vSim3->setEstimate(g2oS12); |
| 2138 | vSim3->setId(0); |
| 2139 | vSim3->setFixed(false); |
| 2140 | vSim3->pCamera1 = pKF1->mpCamera; |
| 2141 | vSim3->pCamera2 = pKF2->mpCamera; |
| 2142 | optimizer.addVertex(vSim3); |
| 2143 | |
| 2144 | // Set MapPoint vertices |
| 2145 | const int N = vpMatches1.size(); |
| 2146 | const vector<MapPoint*> vpMapPoints1 = pKF1->GetMapPointMatches(); |
| 2147 | vector<ORB_SLAM3::EdgeSim3ProjectXYZ*> vpEdges12; |
| 2148 | vector<ORB_SLAM3::EdgeInverseSim3ProjectXYZ*> vpEdges21; |
| 2149 | vector<size_t> vnIndexEdge; |
| 2150 | vector<bool> vbIsInKF2; |
| 2151 | |
| 2152 | vnIndexEdge.reserve(2*N); |
| 2153 | vpEdges12.reserve(2*N); |
| 2154 | vpEdges21.reserve(2*N); |
| 2155 | vbIsInKF2.reserve(2*N); |
| 2156 | |
| 2157 | const float deltaHuber = sqrt(th2); |
| 2158 | |
| 2159 | int nCorrespondences = 0; |
| 2160 | int nBadMPs = 0; |
| 2161 | int nInKF2 = 0; |
| 2162 | int nOutKF2 = 0; |
| 2163 | int nMatchWithoutMP = 0; |
| 2164 | |
| 2165 | vector<int> vIdsOnlyInKF2; |
| 2166 | |
| 2167 | for(int i=0; i<N; i++) |
| 2168 | { |
| 2169 | if(!vpMatches1[i]) |
| 2170 | continue; |
| 2171 | |
| 2172 | MapPoint* pMP1 = vpMapPoints1[i]; |
nothing calls this directly
no test coverage detected