PCL - ICP代碼研讀(五 ) - align函數
- 前言
- align
- align wrapper
前言
接續PCL - ICP代碼研讀(二 ) - Registration架構,本篇主要介紹Registration
類別的align
函數。
computeTransformation
這個純虛擬函數用於估計兩點雲間的轉矩矩陣(final_transformation_
),並同時對輸入點雲input_
做轉換,將結果儲存至output
這個點雲中,可以說是校正算法的核心。
align
函數則是它的wrapper,為computeTransformation
函數做好初始化後,再呼叫該函數。
align
函數有兩個版本,一個需要傳入4 * 4轉換矩陣作為初始解,另一個則假設初始解為單位矩陣,不需要傳入4 * 4矩陣。
align
1
2
3
4
5
6template <typename PointSource, typename PointTarget, typename Scalar> inline void Registration<PointSource, PointTarget, Scalar>::align(PointCloudSource& output, const Matrix4& guess) {
先透過initCompute
函數設定好tree_
及correspondence_estimation_
。
1
2
3
4if (!initCompute()) return;
準備好output
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21// Resize the output dataset output.resize(indices_->size()); // Copy the header output.header = input_->header; // Check if the output will be computed for all points or only a subset if (indices_->size() != input_->size()) { // 只對輸入點雲中索引為indices_的點做align output.width = indices_->size(); // 為何不是output.height = input_->height? output.height = 1; } else { output.width = static_cast<std::uint32_t>(input_->width); output.height = input_->height; } output.is_dense = input_->is_dense; // Copy the point data to output for (std::size_t i = 0; i < indices_->size(); ++i) output[i] = (*input_)[(*indices_)[i]];
目前與point_representation_
相關的代碼還沒看明白。
1
2
3
4
5
6// ? // Set the internal point representation of choice unless otherwise noted if (point_representation_ && !force_no_recompute_) tree_->setPointRepresentation(point_representation_);
converged_
,final_transformation_
,transformation_
及previous_transformation_
這幾個protected
成員變數在computeTransformation
中會用到,這裡先將他們初始化。
1
2
3
4
5
6// Perform the actual transformation computation converged_ = false; final_transformation_ = transformation_ = previous_transformation_ = Matrix4::Identity();
computeTransformation
函數中用到的轉換矩陣是4*4的,這裡用齊次法表示output
,接下來就可以直接用一次矩陣乘法來做旋轉與平移。
1
2
3
4
5
6
7// Right before we estimate the transformation, we set all the point.data[3] values to // 1 to aid the rigid transformation // 齊次坐標的意思? for (std::size_t i = 0; i < indices_->size(); ++i) output[i].data[3] = 1.0;
計算final_transformation_
並更新output
:
1
2
3
4// 注意align函數會修改入參output computeTransformation(output, guess);
PCLBase::deinitCompute
函數為空:
1
2
3
4deinitCompute(); }
align wrapper
這個函數與align(PointCloudSource& output, const Matrix4& guess)
比起來少了一個參數guess
。它是該函數的wrapper,默認guess
為單位矩陣。
1
2
3
4
5
6
7template <typename PointSource, typename PointTarget, typename Scalar> inline void Registration<PointSource, PointTarget, Scalar>::align(PointCloudSource& output) { align(output, Matrix4::Identity()); }
最后
以上就是欢喜书包最近收集整理的关于PCL - ICP代碼研讀(五 ) - align函數的全部内容,更多相关PCL内容请搜索靠谱客的其他文章。
发表评论 取消回复