生活随笔
收集整理的這篇文章主要介紹了
CloudCompare二次开发之如何配置PCL点云库?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 0.引言
- 1.修改兩個CMakeLists.txt文件
- 2.源碼編譯
- 3.測試PCL
0.引言
??因筆者課題涉及點云處理,需要通過PCL進行點云數據分析處理,查閱現有網絡資料,實現了VisualStudio2015(x86)配置PCL1.8.1點云庫(見:VisualStudio如何配置PCL點云庫?)。而筆者對CloudCompare二次開發較為熟悉,希望在CloudCompare中使用PCL進行點云處理,所以本文在VS配置PCL成功的基礎上,實現CloudCompare-2.10.x對PCL的配置,并記錄了實現配置的過程。
1.修改兩個CMakeLists.txt文件
??(1)修改CloudCompare-2.10.x源文件目錄下的CMakeLists.txt
??
# PCL
option( OPTION_BUILD_PCL
"Check to add PCL 3rdParty" ON
)
if ( OPTION_BUILD_PCL
) find_package(PCL REQUIRED
) include_directories( $
{PCL_INCLUDE_DIRS
} ) message($
{PCL_INCLUDE_DIRS
}) link_directories( $
{PCL_LIBRARY_DIRS
} ) message($
{PCL_LIBRARY_DIRS
}) add_definitions( $
{PCL_DEFINITIONS
} )
endif()
??(2)修改CloudCompare-2.10.x源文件的CC目錄下的CMakeLists.txt
??①找到CMakeLists.txt,并打開
??
??②添加PCL配置
??
option( COMPILE_CC_CORE_LIB_WITH_PCL
"Check to compile CC_CORE_LIB with PCL" ON
) # 添加PCL配置
??③添加PCL環境
??
# PCL環境
if(COMPILE_CC_CORE_LIB_WITH_PCL
) find_package(PCL REQUIRED
) include_directories( $
{PCL_INCLUDE_DIRS
} ) #define the PCL_VER_1_8_OR_OLDER preprocessor to compile qPCL with older versions of PCL if ( PCL_VERSION VERSION_LESS
1.8 ) # VERSION_GREATER Works just like
"greater or equal" set_property( TARGET $
{PROJECT_NAME
} APPEND PROPERTY
COMPILE_DEFINITIONS PCL_VER_1_8_OR_OLDER
) endif() # Luca's PCL patch support if( PCL_VERSION VERSION_GREATER
1.7 ) #
from 1.7 the patch was
merged set_property( TARGET $
{PROJECT_NAME
} APPEND PROPERTY
COMPILE_DEFINITIONS LP_PCL_PATCH_ENABLED
) endif() link_directories( $
{PCL_LIBRARY_DIRS
} ) add_definitions( $
{PCL_DEFINITIONS
} ) target_link_libraries( $
{PROJECT_NAME
} $
{PCL_LIBRARIES
}) #指定目標在運行時要尋找的鏈接庫
endif()
2.源碼編譯
??在Cmake中進行配置,會生成PCL相關的文件,并勾選COMPILE_CC_CORE_LIB_WITH_PCL。
??
??
3.測試PCL
??(1)修改mainwindow.ui文件
??①設計按鈕
??
??②編譯.ui
??
??(2)修改mainwindow.h文件
??
void doActionPCLUniformSample();
??(3)修改mainwindow.cpp文件
??①添加均勻采樣頭文件
??
#include <pcl/keypoints/uniform_sampling.h>
??注:若出現找不到pcl文件的情況,需要設置屬性表,具體可參考:VisualStudio如何配置PCL點云庫?。
??②添加均勻采樣實現代碼
??
void MainWindow
::doActionPCLUniformSample()
{ if (getSelectedEntities().size() != 1) { ccLog
::Print(QStringLiteral("只能選擇一個點云實體")); return; } ccHObject
* entity
= getSelectedEntities()[0]; ccPointCloud
* ccCloud
= ccHObjectCaster
::ToPointCloud(entity
); pcl
::PointCloud
<pcl
::PointXYZ
>::Ptr cloud(new pcl
::PointCloud
<pcl
::PointXYZ
>); cloud
->resize(ccCloud
->size()); for (int i
= 0; i
< cloud
->size(); ++i
) { const CCVector3
* point
= ccCloud
->getPoint(i
); cloud
->points
[i
].x
= point
->x
; cloud
->points
[i
].y
= point
->y
; cloud
->points
[i
].z
= point
->z
; } float radius
= QInputDialog
::getDouble(this, QStringLiteral("參數設置"), QStringLiteral("搜索半徑: "), 0.005, 0, 100, 4); pcl
::PointCloud
<pcl
::PointXYZ
>::Ptr filtered(new pcl
::PointCloud
<pcl
::PointXYZ
>); pcl
::UniformSampling<pcl::PointXYZ> us
; us
.setInputCloud(cloud
); us
.setRadiusSearch(radius
); us
.filter(*filtered
); if (!filtered
->empty()) { ccPointCloud
* newPointCloud
= new ccPointCloud(QString("UniformSample")); for (int i
= 0; i
< filtered
->size(); ++i
) { double x
= filtered
->points
[i
].x
; double y
= filtered
->points
[i
].y
; double z
= filtered
->points
[i
].z
; newPointCloud
->addPoint(CCVector3(x
, y
, z
)); } newPointCloud
->setRGBColor(ccColor::Rgba(rand() % 255, rand() % 255, 0, 255)); newPointCloud
->showColors(true); if (ccCloud
->getParent()) { ccCloud
->getParent()->addChild(newPointCloud
); } ccCloud
->setEnabled(false); addToDB(newPointCloud
); refreshAll(); updateUI(); } else { ccCloud
->setEnabled(true); dispToConsole("Warning: example shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE
); }
}
??③添加信號槽函數
??
connect(m_UI
->actionsample
, &
;QAction
::triggered
, this, &
;MainWindow
::doActionPCLUniformSample
);
??(4)生成
??
??(5)結果展示
??①原始點云
??
??②采樣后的點云(相比原始點云,變稀了)
??
參考資料:
[1] 來吧!我在未來等你!. CloudCompare如何進行二次開發的第一步:編譯?; 2023-04-28 [accessed 2023-05-14].
[2] 來吧!我在未來等你!. CloudCompare如何進行二次開發?; 2023-04-19 [accessed 2023-05-14].
[3] 來吧!我在未來等你!. VisualStudio如何配置PCL點云庫?; 2023-05-14 [accessed 2023-05-15].
[4] 點云俠. CloudCompare 二次開發(5)——非插件中的PCL環境配置(均勻采樣為例); 2023-02-17 [accessed 2023-05-14].
總結
以上是生活随笔為你收集整理的CloudCompare二次开发之如何配置PCL点云库?的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。