思路:
1 、下采样(推荐)
2、 三角化骨骼顶点(不推荐)
* This example program shows how to use the operators
* gen_plane_object_model_3d, gen_sphere_object_model_3d_center
* gen_sphere_object_model_3d, gen_cylinder_object_model_3d, and
* gen_box_object_model_3d in HALCON. In this example, a plane,
* two spheres, a cylinder, and a box are set with different poses.
* The generated primitves of the 3D object models are visualized.
*
* Initialize program.
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
create_pose (0.1, 1.5, 88, 106, 337, 224, 'Rp+T', 'gba', 'point', PoseIn)
gen_circle_contour_xld (ContCircle, 200, 200, 100, 0, 6.28318, 'positive', 120)
get_contour_xld (ContCircle, Row, Column)
X := 3 * Row / max([Row,Column]) - 2
Y := 3 * Column / max([Row,Column]) - 2
*
* Create an infinite plane.
gen_plane_object_model_3d ([0,0,0,0,0,0,0], [], [], ObjectModel3DPlane1)
* Create a limited plane.
gen_plane_object_model_3d ([1,1,1,0,50,30,0], X, Y, ObjectModel3DPlane2)
* Create a sphere using pose.
gen_sphere_object_model_3d ([0,0,3,0,0,0,0], 0.5, ObjectModel3DSphere1)
gen_sphere_object_model_3d ([0,0,0,0,0,0,0], 5, ObjectModel3DSphere)
* Create a sphere und position.
gen_sphere_object_model_3d_center (-1, 0, 1, 1, ObjectModel3DSphere2)
* Create a cylinder.
gen_cylinder_object_model_3d ([1,-1,2,0,0,60,0], 0.5, -1, 1, ObjectModel3DCylinder)
gen_cylinder_object_model_3d ([1,-1,2,0,0,60,0], 1, -2, 2, ObjectModel3D)
* Create a box.
gen_box_object_model_3d ([-1,2,1,0,0,90,0], 1, 2, 1, ObjectModel3DBox)
*
* Display the generated primitives.
Instructions[0] := 'Rotate: Left button'
Instructions[1] := 'Zoom: Shift + left button'
Instructions[2] := 'Move: Ctrl + left button'
ObjectModels := [ObjectModel3DPlane1,ObjectModel3DCylinder,ObjectModel3DSphere1,ObjectModel3DSphere2,ObjectModel3DPlane2,ObjectModel3DBox]
Labels := ['Plane1','Cylinder','Sphere1','Sphere2','Plane2','Box']
VisParamName := ['disp_pose_3','color_0','color_1','color_2','color_3','color_4','color_5','alpha_0']
VisParamValue := ['true','green','cyan','yellow','magenta','blue','white',0.5]
visualize_object_model_3d (WindowHandle, ObjectModels, [], PoseIn, VisParamName, VisParamValue, [], Labels, Instructions, PoseOut)
* 推荐
sample_object_model_3d (ObjectModel3DSphere, 'fast', 0.02, [], [], SampledObjectModel3D)
write_object_model_3d (SampledObjectModel3D, 'ply', 'C:/Users/Albert/Desktop/myballdxf1', [], [])
* 不推荐 拿到的点其实就是三角化之后三角形的顶点----骨骼
convex_hull_object_model_3d (ObjectModel3DSphere, ObjectModel3DConvexHull)
* 得到球面上的点
get_object_model_3d_params (ObjectModel3DConvexHull, 'point_coord_x', point_coord_x)
get_object_model_3d_params (ObjectModel3DConvexHull, 'point_coord_y', point_coord_y)
get_object_model_3d_params (ObjectModel3DConvexHull, 'point_coord_z', point_coord_z)
gen_object_model_3d_from_points (point_coord_x, point_coord_y, point_coord_z, ObjectModel3D1)
write_object_model_3d (ObjectModel3D1, 'ply', 'C:/Users/Albert/Desktop/myballdxf', [], [])
骨骼:
下采样:
* 加载图像;
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image7, 'C:/Users/Albert/7 没检测出来/7.tif')
threshold(Image7, Region, -45, 255)
get_domain (Image7, Domain)
difference (Domain, Region, RegionDifference)
paint_region (RegionDifference, Image7, ImageResult, -40, 'fill')
* 有nan 值先取掉
min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
threshold (ImageResult, Region1, Min, Max)
reduce_domain (ImageResult, Region1, ImageReduced)
get_image_size (ImageReduced, Width, Height)
* 生成xy 图
gen_image_surface_first_order (ImageSurface, 'real', 1, 0, 0, 0, 0, Width, Height)
gen_image_surface_first_order (ImageSurface1, 'real', 0, 1, 0, 0, 0, Width, Height)
x:=1
y:=2
z:=1
scale_image (ImageSurface, X, x, 0)
scale_image (ImageSurface1, Y, y, 0)
scale_image (ImageReduced, Z, z, 0)
* 生成点云模型
xyz_to_object_model_3d (X, Y, Z, ObjectModel3D)
write_object_model_3d (ObjectModel3D, 'ply', 'C:/Users/Albert/Desktop/mycloud', [], [])
halcon 案例:
xyz_attrib_to_object_model_3d.hdev