From 4ad3669efd649ef9f0ede221114bd812d03c3b81 Mon Sep 17 00:00:00 2001 From: fengzongbao Date: Fri, 13 Dec 2019 18:46:52 +0800 Subject: [PATCH] exercise: add mass point line test codes --- README.md | 2 +- .../official/Features/moment_of_inertia.py | 18 +++++++++--------- exercises/3.2.example.segment.py | 8 +++++--- exercises/3.2.todo.segment.py | 1 - 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3c55a9b..64e8de1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -For Geeks Python PCL Introduction +Python PCL Introduction For Geeks ============ This is a small python binding to the `pointcloud `_ library. diff --git a/examples/official/Features/moment_of_inertia.py b/examples/official/Features/moment_of_inertia.py index e28aa0b..4e356b7 100644 --- a/examples/official/Features/moment_of_inertia.py +++ b/examples/official/Features/moment_of_inertia.py @@ -2,10 +2,10 @@ # http://pointclouds.org/documentation/tutorials/moment_of_inertia.php#moment-of-inertia import pcl - +import pcl.pcl_visualization def main(): - cloud = pcl.load('./examples/pcldata/tutorials/lamppost.pcd') + cloud = pcl.load('/python-pcl/examples/pcldata/tutorials/lamppost.pcd') # 1.8 # pcl::MomentOfInertiaEstimation feature_extractor; @@ -50,11 +50,11 @@ def main(): # viewer->addPointCloud (cloud, "sample cloud"); # viewer->addCube (min_point_AABB.x, max_point_AABB.x, min_point_AABB.y, max_point_AABB.y, min_point_AABB.z, max_point_AABB.z, 1.0, 1.0, 0.0, "AABB"); ### - viewer = pcl.visualization.PCLVisualizing() + viewer = pcl.pcl_visualization.PCLVisualizering() viewer.SetBackgroundColor(0, 0, 0) - viewer->InitCameraParameters() + # viewer->InitCameraParameters() # viewer->AddPointCloud (cloud, 'sample cloud', 0) - viewer->AddPointCloud(cloud) + # viewer->AddPointCloud(cloud) viewer.AddCube(min_point_AABB.x, max_point_AABB.x, min_point_AABB.y, max_point_AABB.y, min_point_AABB.z, max_point_AABB.z, 1.0, 1.0, 0.0, "AABB") @@ -78,9 +78,9 @@ def main(): middle_vector[1] + mass_center[1], middle_vector[2] + mass_center[2]) z_axis = pcl.PointCloud( minor_vector[0] + mass_center[0], minor_vector[1] + mass_center[1], minor_vector[2] + mass_center[2]) - viewer.AddLine(center, x_axis, 1.0f, 0.0f, 0.0f, "major eigen vector") - viewer.AddLine(center, y_axis, 0.0f, 1.0f, 0.0f, "middle eigen vector") - viewer.AddLine(center, z_axis, 0.0f, 0.0f, 1.0f, "minor eigen vector") + viewer.AddLine(center, x_axis, 1.0, 0.0, 0.0, "major eigen vector") + viewer.AddLine(center, y_axis, 0.0, 1.0, 0.0, "middle eigen vector") + viewer.AddLine(center, z_axis, 0.0, 0.0, 1.0, "minor eigen vector") # while(!viewer->wasStopped()) # { @@ -89,7 +89,7 @@ def main(): # } v = true while v: - v = not(visual.WasStopped()) + v = not(viewer.WasStopped()) # visual.spinOnce (100) # boost::this_thread::sleep (boost::posix_time::microseconds (100000)); diff --git a/exercises/3.2.example.segment.py b/exercises/3.2.example.segment.py index 671739b..2fb805c 100644 --- a/exercises/3.2.example.segment.py +++ b/exercises/3.2.example.segment.py @@ -74,7 +74,6 @@ def main(): cloud_input[indice][0], cloud_input[indice][1], cloud_input[indice][2]]) - if cloud_input[indice][0] < min_x: min_x = cloud_input[indice][0] if cloud_input[indice][1] < min_y: min_y = cloud_input[indice][1] if cloud_input[indice][2] < min_z: min_z = cloud_input[indice][2] @@ -82,10 +81,12 @@ def main(): if cloud_input[indice][0] > max_x: max_x = cloud_input[indice][0] if cloud_input[indice][1] > max_y: max_y = cloud_input[indice][1] if cloud_input[indice][2] > max_z: max_z = cloud_input[indice][2] - print('cluster size:' + str(len(cluster_points))) cluster_cloud = pcl.PointCloud() cluster_cloud.from_list(cluster_points) + # mass center + # mass_center_point = pcl.PointCloud(min_x + (min_x+max_x)/2, min_y + (min_y+max_y)/2, min_z + (min_z+max_z)/2) + # z_axis = pcl.PointCloud(min_x, min_y, min_z) # CLOUD RGB COLOR r = int(cluster_color[j][0]) g = int(cluster_color[j][1]) @@ -94,7 +95,8 @@ def main(): cluster_cloud, r, g, b) # pcl.save(cluster_cloud, str(j) + '.pcd') viewer.AddPointCloud_ColorHandler(cluster_cloud, cluster_pc_color, 'cloud_cluster:' + str(j)) - # viewer.AddCube(min_x, max_x, min_y, max_y, min_z, max_z, 255, 255, 255, 'cloud_cluster:' + str(j)) + # viewer.AddCube(min_x, max_x, min_y, max_y, min_z, max_z, 1.0, 1.0, 1.0, 'cloud_cluster:' + str(j)) + # viewer.AddLine(mass_center_point, z_axis, 0.0, 0.0, 1.0, "minor eigen vector") v = True while v: diff --git a/exercises/3.2.todo.segment.py b/exercises/3.2.todo.segment.py index de2fb3c..5a56245 100644 --- a/exercises/3.2.todo.segment.py +++ b/exercises/3.2.todo.segment.py @@ -68,7 +68,6 @@ def main(): cloud_input[indice][0], cloud_input[indice][1], cloud_input[indice][2]]) - print('cluster size:' + str(len(cluster_points))) cluster_cloud = pcl.PointCloud() cluster_cloud.from_list(cluster_points)