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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

从深度图里面导出边界

發布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 从深度图里面导出边界 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這次我們將學著怎么從一個深度圖里面導出邊界。我們對3種不同種類的點很感興趣:物體的邊框的點,陰影邊框點,和面紗點(在障礙物邊界和陰影邊界),這是一個很典型的現象在通過雷達獲取的3D深度。

下面是代碼

/* \author Bastian Steder */#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/console/parse.h>typedef pcl::PointXYZ PointType;// -------------------- // -----Parameters----- // -------------------- float angular_resolution = 0.5f; pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME; bool setUnseenToMaxRange = false;// -------------- // -----Help----- // -------------- 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"<< "-h this help\n"<< "\n\n"; }// -------------- // -----Main----- // -------------- int main (int argc, char** argv) {// --------------------------------------// -----Parse Command Line Arguments-----// --------------------------------------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";}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, "-r", angular_resolution) >= 0)cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";angular_resolution = pcl::deg2rad (angular_resolution);// ------------------------------------------------------------------// -----Read pcd file or create example point cloud if not given-----// ------------------------------------------------------------------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 ()){std::string filename = argv[pcd_filename_indices[0]];if (pcl::io::loadPCDFile (filename, point_cloud) == -1){cout << "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{cout << "\nNo *.pcd file given => Genarating example point cloud.\n\n";for (float x=-0.5f; x<=0.5f; x+=0.01f){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;}// -----------------------------------------------// -----Create RangeImage from the PointCloud-----// -----------------------------------------------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 ();// --------------------------------------------// -----Open 3D viewer and add point cloud-----// --------------------------------------------pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);viewer.addCoordinateSystem (1.0f, "global");pcl::visualization::PointCloudColorHandlerCustom<PointType> point_cloud_color_handler (point_cloud_ptr, 0, 0, 0);viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");//PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 150, 150, 150);//viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");//viewer.setPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, 2, "range image");// -------------------------// -----Extract borders-----// -------------------------pcl::RangeImageBorderExtractor border_extractor (&range_image);pcl::PointCloud<pcl::BorderDescription> border_descriptions;border_extractor.compute (border_descriptions);// ----------------------------------// -----Show points in 3D viewer-----// ----------------------------------pcl::PointCloud<pcl::PointWithRange>::Ptr border_points_ptr(new pcl::PointCloud<pcl::PointWithRange>),veil_points_ptr(new pcl::PointCloud<pcl::PointWithRange>),shadow_points_ptr(new pcl::PointCloud<pcl::PointWithRange>);pcl::PointCloud<pcl::PointWithRange>& border_points = *border_points_ptr,& veil_points = * veil_points_ptr,& shadow_points = *shadow_points_ptr;for (int y=0; y< (int)range_image.height; ++y){for (int x=0; x< (int)range_image.width; ++x){if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__OBSTACLE_BORDER])border_points.points.push_back (range_image.points[y*range_image.width + x]);if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__VEIL_POINT])veil_points.points.push_back (range_image.points[y*range_image.width + x]);if (border_descriptions.points[y*range_image.width + x].traits[pcl::BORDER_TRAIT__SHADOW_BORDER])shadow_points.points.push_back (range_image.points[y*range_image.width + x]);}}pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> border_points_color_handler (border_points_ptr, 0, 255, 0);viewer.addPointCloud<pcl::PointWithRange> (border_points_ptr, border_points_color_handler, "border points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "border points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> veil_points_color_handler (veil_points_ptr, 255, 0, 0);viewer.addPointCloud<pcl::PointWithRange> (veil_points_ptr, veil_points_color_handler, "veil points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "veil points");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> shadow_points_color_handler (shadow_points_ptr, 0, 255, 255);viewer.addPointCloud<pcl::PointWithRange> (shadow_points_ptr, shadow_points_color_handler, "shadow points");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "shadow points");//-------------------------------------// -----Show points on range image-----// ------------------------------------pcl::visualization::RangeImageVisualizer* range_image_borders_widget = NULL;range_image_borders_widget =pcl::visualization::RangeImageVisualizer::getRangeImageBordersWidget (range_image, -std::numeric_limits<float>::infinity (), std::numeric_limits<float>::infinity (), false,border_descriptions, "Range image with borders");// -------------------------------------//--------------------// -----Main loop-----//--------------------while (!viewer.wasStopped ()){range_image_borders_widget->spinOnce ();viewer.spinOnce ();pcl_sleep(0.01);} }

代碼解釋

在剛開始,我們做命令行解析,從一個磁盤里面讀取點云,我們創造了一個深度圖并把它進行可視化。所有的這些步驟在"Range Image Visualization"里面有講。

這里只有一小點偏差。為了導出邊緣信息,我們要區別出無法到的深度點和超出觀察范圍之外的深度點。接著我們標記一個邊框,觀察不到的點不用標記。因此提供一些測量參數是很重要的。我們將找到一個額外的pcd文件包含如下的值。

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";

他們等一下將融入深度圖里面

range_image.integrateFarRanges (far_ranges);

如果這些值沒有提供,命令行參數-m將被用來賦值,所有不能觀測到地點都被認為很遠距離的點。

if (setUnseenToMaxRange)range_image.setUnseenToMaxRange ();

接下去我們將來到與邊緣導出相關的部分

pcl::RangeImageBorderExtractor border_extractor (&range_image); pcl::PointCloud<pcl::BorderDescription> border_descriptions; border_extractor.compute (border_descriptions);

上面將會創建RangeImageBorderExtractor這個類,給一個深度圖,計算邊緣信息,并把它存在border_descriptions里面。

最后 ,viewer.addCoordinateSystem (1.0f, "global");可能會出現錯誤,把代碼改成viewer.addCoordinateSystem (1.0f);

直接運行它

/range_image_border_extraction -m

使用一個點云文件

./range_image_border_extraction <point_cloud.pcd>

?

?

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的从深度图里面导出边界的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。