index:.../3D-Object-Model/Segmentation/Fit_primitives_object_model_3d.hdev
* ***********************************************************************
* This example program shows how to use the operator
* fit_object_model_3d in HALCON. First, the 2.5D input image is
* segmented with a simple segmentation. Then, a fitting is applied
* using a least squares adjustment. Finally, the radius of the fitted
* cylinder is shown.
* ***********************************************************************
这些例程输入都2.5D图像,包含了立体信息的
* Input: 2.5D image
read_image (XYZ, '3d_machine_vision/segmentation/3d_primitives_xyz_02.tif')
* Access to (x-, y-, z-)coordinates
切分为三通道
access_channel (XYZ, X, 1)
access_channel (XYZ, Y, 2)
access_channel (XYZ, Z, 3)
* Segment cylinder manually
做阈值化
threshold (Z, Region, 0.0, 0.83)
reduce_domain (X, Region, XTmp)
* Create an object model 3d from the segmented region
xyz_to_object_model_3d (XTmp, Y, Z, ObjectModel3DID)
ParFitting := ['primitive_type','fitting_algorithm','min_radius','max_radius','output_xyz_mapping']
ValFitting := ['cylinder','least_squares_huber',0.01,0.1,'true']
* Apply the fitting
fit_primitives_object_model_3d (ObjectModel3DID, ParFitting, ValFitting, ObjectModel3DOutID)
上面从分割出来的区域做了一个3d模型,里面参数设置都在帮助文档,但帮助文档说一般不设置也可以。
* Clear the object model that is no longer used
clear_object_model_3d (ObjectModel3DID)
清除了模型句柄
* Display the result of the fitting
dev_display_fitting_results (RegionCylinder, RegionSphere, RegionPlane, RegionNone, ObjectModel3DOutID, WindowHandle, [])
在这个函数里面
object_model_3d_to_xyz (XTmp, YTmp, ZTmp, ObjectModel3DOutID[Index], 'from_xyz_map', [], [])
get_domain (XTmp, DomainTmp)
get_object_model_3d_params (ObjectModel3DOutID[Index], 'has_primitive_data', ParamValue)
if (ParamValue == 'true')
get_object_model_3d_params (ObjectModel3DOutID[Index], 'primitive_parameter', GenParamValuesP)
get_object_model_3d_params (ObjectModel3DOutID[Index], 'primitive_type', ParamValue)
说白了,就是用前面自己建立的模板匹配了自己后的ObjectModel3DOutID这个东西,然后在显示函数中把他的参数读出来显示
primitive_parameter 这个参数里面第六个值就是半径,圆,圆柱等等