日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

PCL点云特征描述与提取(4)

發(fā)布時(shí)間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PCL点云特征描述与提取(4) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
如何從一個(gè)深度圖像(range image)中提取NARF特征

代碼解析narf_feature_extraction.cpp

#include <iostream>#include <boost/thread/thread.hpp>
#include <pcl/range_image/range_image.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/features/range_image_border_extractor.h>
#include <pcl/keypoints/narf_keypoint.h>
#include <pcl/features/narf_descriptor.h>
#include <pcl/console/parse.h>typedef pcl::PointXYZ PointType;//參數(shù)的設(shè)置
float angular_resolution = 0.5f;
float support_size = 0.2f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool setUnseenToMaxRange = false;
bool rotation_invariant = true;//命令幫助
void 
printUsage (const char* progName)
{std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"<< "Options:\n"<< "-------------------------------------------\n"<< "-r <float>   angular resolution in degrees (default "<<angular_resolution<<")\n"<< "-c <int>     coordinate frame (default "<< (int)coordinate_frame<<")\n"<< "-m           Treat all unseen points to max range\n"<< "-s <float>   support size for the interest points (diameter of the used sphere - ""default "<<support_size<<")\n"<< "-o <0/1>     switch rotational invariant version of the feature on/off"<<               " (default "<< (int)rotation_invariant<<")\n"<< "-h           this help\n"<< "\n\n";
}void 
setViewerPose (pcl::visualization::PCLVisualizer& viewer, const Eigen::Affine3f& viewer_pose)//setViewerPose
{Eigen::Vector3f pos_vector = viewer_pose * Eigen::Vector3f (0, 0, 0);Eigen::Vector3f look_at_vector = viewer_pose.rotation () * Eigen::Vector3f (0, 0, 1) + pos_vector;Eigen::Vector3f up_vector = viewer_pose.rotation () * Eigen::Vector3f (0, -1, 0);viewer.setCameraPosition (pos_vector[0], pos_vector[1], pos_vector[2],look_at_vector[0], look_at_vector[1], look_at_vector[2],up_vector[0], up_vector[1], up_vector[2]);
}int 
main (int argc, char** argv)
{// 設(shè)置參數(shù)檢測if (pcl::console::find_argument (argc, argv, "-h") >= 0){printUsage (argv[0]);return 0;}if (pcl::console::find_argument (argc, argv, "-m") >= 0){setUnseenToMaxRange = true;cout << "Setting unseen values in range image to maximum range readings.\n";}if (pcl::console::parse (argc, argv, "-o", rotation_invariant) >= 0)cout << "Switching rotation invariant feature version "<< (rotation_invariant ? "on" : "off")<<".\n";int tmp_coordinate_frame;if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0){coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";}if (pcl::console::parse (argc, argv, "-s", support_size) >= 0)cout << "Setting support size to "<<support_size<<".\n";if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";angular_resolution = pcl::deg2rad (angular_resolution);//打開一個(gè)磁盤中的.pcd文件  但是如果沒有指定就會自動生成pcl::PointCloud<PointType>::Ptr    point_cloud_ptr (new pcl::PointCloud<PointType>);pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr;pcl::PointCloud<pcl::PointWithViewpoint> far_ranges;Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");if (!pcd_filename_indices.empty ())   //檢測是否有far_ranges.pcd
  {std::string filename = argv[pcd_filename_indices[0]];if (pcl::io::loadPCDFile (filename, point_cloud) == -1){cerr << "Was not able to open file \""<<filename<<"\".\n";printUsage (argv[0]);return 0;}scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],point_cloud.sensor_origin_[1],point_cloud.sensor_origin_[2])) *Eigen::Affine3f (point_cloud.sensor_orientation_);std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd";if (pcl::io::loadPCDFile (far_ranges_filename.c_str (), far_ranges) == -1)std::cout << "Far ranges file \""<<far_ranges_filename<<"\" does not exists.\n";}else{setUnseenToMaxRange = true;cout << "\nNo *.pcd file given => Genarating example point cloud.\n\n";for (float x=-0.5f; x<=0.5f; x+=0.01f)   //如果沒有打開的文件就生成一個(gè)矩形的點(diǎn)云
    {for (float y=-0.5f; y<=0.5f; y+=0.01f){PointType point;  point.x = x;  point.y = y;  point.z = 2.0f - y;point_cloud.points.push_back (point);}}point_cloud.width = (int) point_cloud.points.size ();  point_cloud.height = 1;}//從點(diǎn)云中建立生成深度圖float noise_level = 0.0;    float min_range = 0.0f;int border_size = 1;boost::shared_ptr<pcl::RangeImage> range_image_ptr (new pcl::RangeImage);pcl::RangeImage& range_image = *range_image_ptr;   range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);range_image.integrateFarRanges (far_ranges);if (setUnseenToMaxRange)range_image.setUnseenToMaxRange ();//打開3D viewer并加入點(diǎn)云pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 0, 0, 0);viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image");//viewer.addCoordinateSystem (1.0f, "global");//PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 150, 150, 150);//viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");
  viewer.initCameraParameters ();setViewerPose (viewer, range_image.getTransformationToWorldSystem ());//顯示pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");range_image_widget.showRangeImage (range_image);//提取NARF特征pcl::RangeImageBorderExtractor range_image_border_extractor;    //申明深度圖邊緣提取器pcl::NarfKeypoint narf_keypoint_detector;                       //narf_keypoint_detector為點(diǎn)云對象
narf_keypoint_detector.setRangeImageBorderExtractor (&range_image_border_extractor);narf_keypoint_detector.setRangeImage (&range_image);narf_keypoint_detector.getParameters ().support_size = support_size;    //獲得特征提取的大小
  pcl::PointCloud<int> keypoint_indices;narf_keypoint_detector.compute (keypoint_indices);std::cout << "Found "<<keypoint_indices.points.size ()<<" key points.\n";// ----------------------------------------------// -----Show keypoints in range image widget-----// ----------------------------------------------//for (size_t i=0; i<keypoint_indices.points.size (); ++i)//range_image_widget.markPoint (keypoint_indices.points[i]%range_image.width,//keypoint_indices.points[i]/range_image.width);//在3Dviewer顯示提取的特征信息pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_ptr (new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>& keypoints = *keypoints_ptr;keypoints.points.resize (keypoint_indices.points.size ());for (size_t i=0; i<keypoint_indices.points.size (); ++i)keypoints.points[i].getVector3fMap () = range_image.points[keypoint_indices.points[i]].getVector3fMap ();pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (keypoints_ptr, 0, 255, 0);viewer.addPointCloud<pcl::PointXYZ> (keypoints_ptr, keypoints_color_handler, "keypoints");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");//在關(guān)鍵點(diǎn)提取NARF描述子std::vector<int> keypoint_indices2;keypoint_indices2.resize (keypoint_indices.points.size ());for (unsigned int i=0; i<keypoint_indices.size (); ++i) // This step is necessary to get the right vector typekeypoint_indices2[i]=keypoint_indices.points[i];      ///建立NARF關(guān)鍵點(diǎn)的索引向量,此矢量作為NARF特征計(jì)算的輸入來使用
pcl::NarfDescriptor narf_descriptor (&range_image, &keypoint_indices2);//創(chuàng)建narf_descriptor對象。并給了此對象輸入數(shù)據(jù)(特征點(diǎn)索引和深度像)narf_descriptor.getParameters ().support_size = support_size;//support_size確定計(jì)算描述子時(shí)考慮的區(qū)域大小narf_descriptor.getParameters ().rotation_invariant = rotation_invariant;    //設(shè)置旋轉(zhuǎn)不變的NARF描述子pcl::PointCloud<pcl::Narf36> narf_descriptors;               //創(chuàng)建Narf36的點(diǎn)類型輸入點(diǎn)云對象并進(jìn)行實(shí)際計(jì)算narf_descriptor.compute (narf_descriptors);                 //計(jì)算描述子cout << "Extracted "<<narf_descriptors.size ()<<" descriptors for "   //打印輸出特征點(diǎn)的數(shù)目和提取描述子的數(shù)目<<keypoint_indices.points.size ()<< " keypoints.\n";//主循環(huán)函數(shù)while (!viewer.wasStopped ()){range_image_widget.spinOnce ();  // process GUI events
    viewer.spinOnce ();pcl_sleep(0.01);}
}

編譯運(yùn)行./narf_feature_extraction -m

這將自動生成一個(gè)呈矩形的點(diǎn)云,檢測的特征點(diǎn)處在角落處,參數(shù)-m是必要的,因?yàn)榫匦沃車膮^(qū)域觀測不到,但是屬于邊界部分,因此系統(tǒng)無法檢測到這部分區(qū)域的特征點(diǎn),選項(xiàng)-m將看不到的區(qū)域改變到最大范圍讀取,從而使系統(tǒng)能夠使用這些邊界區(qū)域。

(2)特征描述算子算法基準(zhǔn)化分析

使用FeatureEvaluationFramework類對不同的特征描述子算法進(jìn)行基準(zhǔn)測試,基準(zhǔn)測試框架可以測試不同種類的特征描述子算法,通過選擇輸入點(diǎn)云,算法參數(shù),下采樣葉子大小,搜索閥值等獨(dú)立變量來進(jìn)行測試。

使用FeatureCorrespondenceTest類執(zhí)行一個(gè)單一的“基于特征的對應(yīng)估計(jì)測試”執(zhí)行以下的操作

?? 1.FeatureCorrespondenceTest類取兩個(gè)輸入點(diǎn)云(源與目標(biāo)) 它將指定算法和參數(shù),在每個(gè)點(diǎn)云中計(jì)算特征描述子

? 2.基于n_D特征空間中的最近鄰元素搜索,源點(diǎn)云中的每個(gè)特征將和目標(biāo)點(diǎn)云中對應(yīng)的特征相對照

? 3 。對于每一個(gè)點(diǎn),系統(tǒng)將把估計(jì)的目標(biāo)點(diǎn)的三維位置和之前已知的實(shí)際位置相比

?4 。如果這兩個(gè)點(diǎn)很接近(取決與決定的閥值)那么對應(yīng)就成功,否則失敗

?5 計(jì)算并保存成功和失敗的總數(shù),以便進(jìn)一步分析

?

?

微信公眾號號可掃描二維碼一起共同學(xué)習(xí)交流

總結(jié)

以上是生活随笔為你收集整理的PCL点云特征描述与提取(4)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。