[python][pcl]python-pcl案例之crophull

测试环境:

pcl==1.13.0

python-pcl==0.3.1

python==3.7

代码:

# -*- coding: utf-8 -*-
from __future__ import print_function

import numpy as np
import pcl


def main():
    # http://www.pcl-users.org/CropHull-filter-question-td4030345.html
    datacloud = pcl.load(
        '../examples/pcldata/tutorials/table_scene_mug_stereo_textured.pcd')

    print(datacloud)

    filterCloud = pcl.PointCloud()
    vt = pcl.Vertices()

    # // inside point
    # cloud->push_back(pcl::PointXYZ(M_PI * 0.3, M_PI * 0.3, 0));
    # // hull points
    # cloud->push_back(pcl::PointXYZ(0,0,0));
    # cloud->push_back(pcl::PointXYZ(M_PI,0,0));
    # cloud->push_back(pcl::PointXYZ(M_PI,M_PI*0.5,0));
    # cloud->push_back(pcl::PointXYZ(0,M_PI*0.5,0));
    # cloud->push_back(pcl::PointXYZ(0,0,0));
    # // outside point
    # cloud->push_back(pcl::PointXYZ(-M_PI * 0.3, -M_PI * 0.3, 0));

    points_2 = np.array([
        [1 * 0.3, 1 * 0.3, 0],
        [0, 0, 0],
        [1, 0, 0],
        [1, 1 * 0.5, 0],
        [0, 1 * 0.5, 0],
        [0, 0, 0],
        [-1 * 0.3, -1 * 0.3, 0]
    ], dtype=np.float32)
    filterCloud.from_array(points_2)
    print(filterCloud)

    vertices_point_1 = np.array([1, 2, 3, 4, 5], dtype=np.int)
    vt.from_array(vertices_point_1)

    # print(vt)
    # vt.vertices.push_back(1)
    # vt.vertices.push_back(2)
    # vt.vertices.push_back(3)
    # vt.vertices.push_back(4)
    # vt.vertices.push_back(5)
    # vertices = vector[pcl.Vertices]
    # vertices.push_back(vt)

    outputCloud = pcl.PointCloud()
    # crophull = pcl.CropHull()
    # crophull.setInputCloud(datacloud)
    crophull = datacloud.make_crophull()
    # crophull.setHullIndices(vertices)
    # crophull.setHullIndices(vt)
    # crophull.setHullCloud(filterCloud)
    # crophull.setDim(2)
    # crophull.setCropOutside(false)
    crophull.SetParameter(filterCloud, vt)

    # indices = vector[int]
    # cropHull.filter(indices);
    # outputCloud = cropHull.filter();
    # print("before: " + outputCloud)
    crophull.Filtering(outputCloud)
    print(outputCloud)

    # Viewer
    # // pcl::visualization::CloudViewer viewer ("Cluster viewer");
    # // viewer.showCloud(colored_cloud);

    # pcl.visualization.CloudViewer

    # Write Point
    # pcl::PCDWriter writer;
    # std::stringstream ss;
    # ss << "min_cut_seg" << ".pcd";
    # // writer.write<pcl::PointXYZRGB> (ss.str (), *cloud, false);
    # pcl::io::savePCDFile(ss.str(), *outputCloud, false);


if __name__ == "__main__":
    # import cProfile
    # cProfile.run('main()', sort='time')
    main()

输出:

<PointCloud of 307200 points>
<PointCloud of 7 points>
filter: outputCloud size = 307200
<PointCloud of 307200 points>

Process finished with exit code 0

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FL1623863129

你的打赏是我写文章最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值