[python][pcl]python-pcl案例之3dharris

测试环境:

pcl==1.13.0

python-pcl==0.3.1

python==3.7

代码:

# -*- coding: utf-8 -*-
# http://virtuemarket-lab.blogspot.jp/2015/03/harris.html
import pcl
import numpy as np
import pcl.pcl_visualization


def main():
    # pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    # pcl::io::loadPCDFile<pcl::PointXYZ> (argv[1], *cloud);
    # cloud = pcl.load("table_scene_mug_stereo_textured.pcd")
    # cloud = pcl.load(r'D:\pythonspace\python-pcl-master\examples\pcldata\tutorials\table_scene_mug_stereo_textured.pcd')
    cloud = pcl.load(r'D:\pythonspace\python-pcl-master\examples\pcldata\tutorials\table_scene_mug_stereo_textured.pcd')
    print("cloud points : " + str(cloud.size))

    # pcl::HarrisKeypoint3D<pcl::PointXYZ, pcl::PointXYZI> detector;
    # detector.setNonMaxSupression (true);
    # detector.setRadius (0.01);
    # //detector.setRadiusSearch (100);
    # detector.setInputCloud(cloud);
    # pcl::PointCloud<pcl::PointXYZI>::Ptr keypoints(new pcl::PointCloud<pcl::PointXYZI>());
    # detector.compute(*keypoints);
    ###
    detector = cloud.make_HarrisKeypoint3D()
    detector.set_NonMaxSupression(True)
    detector.set_Radius(0.01)
    # detector.set_NonMaxSupression (False)
    # detector.set_RadiusSearch (100)
    keypoints = detector.compute()

    # std::cout << "keypoints detected: " << keypoints->size() << std::endl;
    print("keypoints detected: " + str(keypoints.size))

    # pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints3D(new pcl::PointCloud<pcl::PointXYZ>());
    # pcl::PointXYZ tmp;
    # double max = 0,min=0;
    # for(pcl::PointCloud<pcl::PointXYZI>::iterator i = keypoints->begin(); i!= keypoints->end(); i++)
    #     tmp = pcl::PointXYZ((*i).x,(*i).y,(*i).z);
    #     if ((*i).intensity>max )
    #         std::cout << (*i) << " coords: " << (*i).x << ";" << (*i).y << ";" << (*i).z << std::endl;
    #         max = (*i).intensity;
    #     if ((*i).intensity<min)
    #         min = (*i).intensity;
    #     keypoints3D->push_back(tmp);
    #
    # std::cout << "maximal responce: "<< max << " min responce:  "<< min<<std::endl;
    ###
    keypoints3D = pcl.PointCloud()
    max = -999
    min = 999

    count = 0
    points = np.zeros((keypoints.size, 3), dtype=np.float32)
    # Generate the data
    for i in range(0, keypoints.size):
        # set Point Plane
        points[i][0] = keypoints[i][0]
        points[i][1] = keypoints[i][1]
        points[i][2] = keypoints[i][2]
        intensity = keypoints[i][3]
        if intensity > max:
            print("coords: " + str(keypoints[i][0]) + ";" +
                  str(keypoints[i][1]) + ";" + str(keypoints[i][2]))
            max = intensity

        if intensity < min:
            min = intensity

        count = count + 1

    points.resize(count, 3)
    print(points)
    keypoints3D.from_array(points)
    print("maximal responce: " + str(max) + " min responce:  " + str(min))

    # //show point cloud
    # pcl::visualization::PCLVisualizer viewer ("3D Viewer");
    # pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> pccolor(cloud, 255, 255, 255);
    # pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> kpcolor(keypoints3D, 255, 0, 0);
    # viewer.addPointCloud(cloud, pccolor, "testimg.png");
    # viewer.addPointCloud(keypoints3D, kpcolor,"keypoints.png");
    # viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints.png");
    ##
    viewer = pcl.pcl_visualization.PCLVisualizering('3D Viewer')
    pccolor = pcl.pcl_visualization.PointCloudColorHandleringCustom(
        cloud, 255, 255, 255)
    kpcolor = pcl.pcl_visualization.PointCloudColorHandleringCustom(
        keypoints3D, 255, 0, 0)
    # OK
    viewer.AddPointCloud_ColorHandler(cloud, pccolor)
    viewer.AddPointCloud_ColorHandler(keypoints3D, kpcolor, b'keypoints')

    # viewer.AddPointCloud_ColorHandler(cloud, pccolor, "testimg.png", 0)
    # viewer.AddPointCloud_ColorHandler(keypoints3D, kpcolor, str('keypoints.png'), 0)
    # need? : AddPointCloud_ColorHandler Function Succeded
    # viewer.SetPointCloudRenderingProperties (pcl.pcl_visualization.PCLVISUALIZER_POINT_SIZE, 7, b'keypoints.png')
    ###

    v = True
    while v:
        v = not(viewer.WasStopped())
        viewer.SpinOnce()
        # sleep(0.01)


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

结果:

 pcd文件下载: https://github.com/strawlab/python-pcl/blob/master/examples/pcldata/tutorials/table_scene_mug_stereo_textured.pcd

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

FL1623863129

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

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

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

打赏作者

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

抵扣说明:

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

余额充值