質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
参照

参照は、プログラミングにおいて変数や関数といったメモリ空間上での所在を指示するデータのことを指します。その中にはデータ自体は含まれず、他の場所にある情報を間接的に指示するプログラムです。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

3618閲覧

PCLの円柱当てはめ結果の参照方法が知りたい

lime00

総合スコア25

参照

参照は、プログラミングにおいて変数や関数といったメモリ空間上での所在を指示するデータのことを指します。その中にはデータ自体は含まれず、他の場所にある情報を間接的に指示するプログラムです。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2021/01/18 09:03

PointCloudLibraryによるCylinder model segmentationによって、点群の円柱パラメータを表示することができました。次にこの7個のパラメータをプログラム内で参照し、別の変数に代入するなどしたいのですが、やり方がわかりません。
どのようにコーディングすれば、各パラメータの参照が可能となるでしょうか。よろしくお願い致します。

サンプルプログラム

C++

1#include <pcl/ModelCoefficients.h> 2#include <pcl/io/pcd_io.h> 3#include <pcl/point_types.h> 4#include <pcl/filters/extract_indices.h> 5#include <pcl/filters/passthrough.h> 6#include <pcl/features/normal_3d.h> 7#include <pcl/sample_consensus/method_types.h> 8#include <pcl/sample_consensus/model_types.h> 9#include <pcl/segmentation/sac_segmentation.h> 10 11typedef pcl::PointXYZ PointT; 12 13int 14main (int argc, char** argv) 15{ 16 // All the objects needed 17 pcl::PCDReader reader; 18 pcl::PassThrough<PointT> pass; 19 pcl::NormalEstimation<PointT, pcl::Normal> ne; 20 pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; 21 pcl::PCDWriter writer; 22 pcl::ExtractIndices<PointT> extract; 23 pcl::ExtractIndices<pcl::Normal> extract_normals; 24 pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT> ()); 25 26 // Datasets 27 pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>); 28 pcl::PointCloud<PointT>::Ptr cloud_filtered (new pcl::PointCloud<PointT>); 29 pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>); 30 pcl::PointCloud<PointT>::Ptr cloud_filtered2 (new pcl::PointCloud<PointT>); 31 pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2 (new pcl::PointCloud<pcl::Normal>); 32 pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients), coefficients_cylinder (new pcl::ModelCoefficients); 33 pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices), inliers_cylinder (new pcl::PointIndices); 34 35 // Read in the cloud data 36 reader.read ("table_scene_mug_stereo_textured.pcd", *cloud); 37 std::cerr << "PointCloud has: " << cloud->size () << " data points." << std::endl; 38 39 // Build a passthrough filter to remove spurious NaNs 40 pass.setInputCloud (cloud); 41 pass.setFilterFieldName ("z"); 42 pass.setFilterLimits (0, 1.5); 43 pass.filter (*cloud_filtered); 44 std::cerr << "PointCloud after filtering has: " << cloud_filtered->size () << " data points." << std::endl; 45 46 // Estimate point normals 47 ne.setSearchMethod (tree); 48 ne.setInputCloud (cloud_filtered); 49 ne.setKSearch (50); 50 ne.compute (*cloud_normals); 51 52 // Create the segmentation object for the planar model and set all the parameters 53 seg.setOptimizeCoefficients (true); 54 seg.setModelType (pcl::SACMODEL_NORMAL_PLANE); 55 seg.setNormalDistanceWeight (0.1); 56 seg.setMethodType (pcl::SAC_RANSAC); 57 seg.setMaxIterations (100); 58 seg.setDistanceThreshold (0.03); 59 seg.setInputCloud (cloud_filtered); 60 seg.setInputNormals (cloud_normals); 61 // Obtain the plane inliers and coefficients 62 seg.segment (*inliers_plane, *coefficients_plane); 63 std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl; 64 65 // Extract the planar inliers from the input cloud 66 extract.setInputCloud (cloud_filtered); 67 extract.setIndices (inliers_plane); 68 extract.setNegative (false); 69 70 // Write the planar inliers to disk 71 pcl::PointCloud<PointT>::Ptr cloud_plane (new pcl::PointCloud<PointT> ()); 72 extract.filter (*cloud_plane); 73 std::cerr << "PointCloud representing the planar component: " << cloud_plane->size () << " data points." << std::endl; 74 writer.write ("table_scene_mug_stereo_textured_plane.pcd", *cloud_plane, false); 75 76 // Remove the planar inliers, extract the rest 77 extract.setNegative (true); 78 extract.filter (*cloud_filtered2); 79 extract_normals.setNegative (true); 80 extract_normals.setInputCloud (cloud_normals); 81 extract_normals.setIndices (inliers_plane); 82 extract_normals.filter (*cloud_normals2); 83 84 // Create the segmentation object for cylinder segmentation and set all the parameters 85 seg.setOptimizeCoefficients (true); 86 seg.setModelType (pcl::SACMODEL_CYLINDER); 87 seg.setMethodType (pcl::SAC_RANSAC); 88 seg.setNormalDistanceWeight (0.1); 89 seg.setMaxIterations (10000); 90 seg.setDistanceThreshold (0.05); 91 seg.setRadiusLimits (0, 0.1); 92 seg.setInputCloud (cloud_filtered2); 93 seg.setInputNormals (cloud_normals2); 94 95 // Obtain the cylinder inliers and coefficients 96 seg.segment (*inliers_cylinder, *coefficients_cylinder); 97 std::cerr << "Cylinder coefficients: " << *coefficients_cylinder << std::endl; 98 99 // Write the cylinder inliers to disk 100 extract.setInputCloud (cloud_filtered2); 101 extract.setIndices (inliers_cylinder); 102 extract.setNegative (false); 103 pcl::PointCloud<PointT>::Ptr cloud_cylinder (new pcl::PointCloud<PointT> ()); 104 extract.filter (*cloud_cylinder); 105 if (cloud_cylinder->points.empty ()) 106 std::cerr << "Can't find the cylindrical component." << std::endl; 107 else 108 { 109 std::cerr << "PointCloud representing the cylindrical component: " << cloud_cylinder->size () << " data points." << std::endl; 110 writer.write ("table_scene_mug_stereo_textured_cylinder.pcd", *cloud_cylinder, false); 111 } 112 return (0); 113}

円柱当てはめ結果

[pcl::SACSegmentationFromNormals::initSACModel] Using a model of type: SACMODEL_CYLINDER [pcl::SACSegmentationFromNormals::initSACModel] Setting radius limits to 0.000000/0.100000 [pcl::SACSegmentationFromNormals::initSACModel] Setting normal distance weight to 0.100000 [pcl::SACSegmentationFromNormals::initSAC] Using a method of type: SAC_RANSAC with a model threshold of 0.050000 [pcl::SampleConsensusModelCylinder::optimizeModelCoefficients] LM solver finished with exit code 2, having a residual norm of 0.322616. Initial solution: 0.0452105 0.0924601 0.790215 0.20495 -0.721649 -0.661225 0.0422902 Final solution: 0.0452105 0.0924601 0.790215 0.20495 -0.721649 -0.661225 0.0396354 Cylinder coefficients: header: seq: 0 stamp: 0.000000000 frame_id: values[] values[0]: 0.0452105 values[1]: 0.0924601 values[2]: 0.790215 values[3]: 0.20495 values[4]: -0.721649 values[5]: -0.661225 values[6]: 0.0396354 PointCloud representing the cylindrical component: 8625 data points.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

pcl::ModelCoefficientsvalues というメンバ変数 ( 型は std::vector<float> ) を持っており、出力に表示されているのはその内容のようです。
ですので coefficients_cylinder->values をコピーするなりそのまま使うなりするのが良いのではないでしょうか。

API ドキュメントの該当箇所へのリンクも併せて置いておきます。

投稿2021/01/19 02:04

編集2021/01/19 02:08
yaito3014

総合スコア176

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問