一、需求原因
因为笔者对pcl库更为熟悉,希望将halcon的部分功能通过c++实现然后用pcl库处理,所以需要将halcon库处理的部分转为pcl库可处理的数据。
二、功能实现
已有halcon在c++编译环境的情况,已知ObjectModel3D为halcon处理好的3D模型;
//此处省略halcon配置环境与头文件
//此处省略PCL库配置环境与头文件
HTuple hv_x;
HTuple hv_y;
HTuple hv_z;
HTuple hv_num;
//获取Halcon的3D模型的x/y/z数据与点的数量num
GetObjectModel3dParams(ObjectModel3d,"point_coord_x",&hv_x);
GetObjectModel3dParams(ObjectModel3d,"point_coord_y",&hv_y);
GetObjectModel3dParams(ObjectModel3d,"point_coord_z",&hv_z);
GetObjectModel3dParams(ObjectModel3d,"num_points",&hv_num);
double x_mid = (hv_x.TupleMax().D() + hv_x.TupleMin().D()) / 2;
double y_mid = (hv_y.TupleMax().D() + hv_y.TupleMin().D()) / 2;
double z_mid = (hv_z.TupleMax().D() + hv_z.TupleMin().D()) / 2;
int num = hv_num[0].I();
pcl::PointCloud<pcl::PointXYZ> pclCloud;
pclCloud.points.resize(num);
pcl::PointCloud<pcl::PointXYZ> cloud;
for(int i = 0;i < num ;++i)
{
pcl::PointXYZ& pclCloud = pclCloud.points[i];
pclPoint.x = hv_x[i].D() - x_mid;
pclPoint.y = hv_x[i].D() - y_mid;
pclPoint.z = hv_x[i].D() - z_mid;
cloud.push_back(pclPoint);
}
pcl::io::savePCDFile("PointCloud.pcd",cloud);
三、关键函数解释
函数名:
GetObjectModel3dParams()
函数原型(halcon):
get_object_model_3d_params( : : ObjectModel3D, GenParamName : GenParamValue)
函数解释:
参考链接:http://t.****img.cn/p2fiO
如果失效则:【四】3D Object Model之测量Features——get_object_model_3d_params()算子_c++的getobjectmodel3dparams()-****博客