コード
#include "stdafx.h"
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/io.h>
#include <pcl/keypoints/harris_keypoint3D.h>
#include <pcl/visualization/pcl_visualizer.h>
int _tmain(int argc, _TCHAR* argv[])
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile<pcl::PointXYZ> (argv[1], *cloud);
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);
std::cout << "keypoints detected: " << keypoints->size() << std::endl;
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;
//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");
while (!viewer.wasStopped ())
{
viewer.spinOnce();
pcl_sleep (0.01);
}
return (0);
}
実行結果
画像では少々わかりにくいが、いわゆる角のような場所に点が加わっているのがわかると思う。
一ヶ月ほど更新を休む必要ができたため次回の更新は未定とする(もともと不定期な更新であるが)