* ***********************************************************************

* This example program shows how to use the operator

* segment_object_model_3d in HALCON. First, the 2.5D

* input image is segmented. Additionally, with the same

* operator, a fitting is performed. The result of the

* 3D segmentation is converted to a region and is

* displayed. Finally, the values of the fitted radii

* for the cylinders and spheres are visualized.

* 首先,分割2.5D输入图像,转化为适当的3D Model,

* 并分割成sub Models(segment_object_model_3d),sub Models转化为区域并显示。

* 最终,圆柱形和球形标示半径并图形化显示。

* ***********************************************************************

dev_update_off ()

dev_close_window ()

* Input: 2.5D image

* 读取:2.5D图像

read_image (XYZ, '3d_machine_vision/segmentation/3d_primitives_xyz_01.tif')

dev_open_window_fit_image (XYZ, 0, 0, -1, -1, WindowHandle)

set_display_font (WindowHandle, 16, 'mono', 'true', 'false')

* Access to (x-, y-, z-)coordinates

* 读取(X,Y,Z)坐标通道数据

access_channel (XYZ, X, 1)

access_channel (XYZ, Y, 2)

access_channel (XYZ, Z, 3)

*

Message := 'Generate a 3D object model from an'

Message[1] := 'XYZ image and segment primitives'

Message[2] := '(spheres, cylinders, planes) in it:'

dev_display (Z)

disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')

disp_continue_message (WindowHandle, 'black', 'true')

stop ()

* Prepare the segmentation

* 准备分割

xyz_to_object_model_3d (X, Y, Z, ObjectModel3DID)

prepare_object_model_3d (ObjectModel3DID, 'segmentation', 'false', 'max_area_holes', 100)

ParSegmentation := ['max_orientation_diff','max_curvature_diff','output_xyz_mapping','min_area']

ValSegmentation := [0.13,0.11,'true',150]

ParFitting := ['primitive_type','fitting_algorithm']

ValFitting := ['all','least_squares_huber']

* Segmentation and fitting is done in one step,

* because the parameter 'fitting' is set to 'true' by default

* 分割和适应性一步完成

* 因为参数'fitting' 默认设置为'true'

segment_object_model_3d (ObjectModel3DID, [ParSegmentation,ParFitting], \

[ValSegmentation,ValFitting], ObjectModel3DOutID)

* Clear the object model that is no longer used.

clear_object_model_3d (ObjectModel3DID)

* Show the result of the segmentation

* 显示分割结果

dev_set_colored (12)

for Index := 0 to |ObjectModel3DOutID| - 1 by 1

object_model_3d_to_xyz (XTmp, YTmp, ZTmp, ObjectModel3DOutID[Index], 'from_xyz_map', [], [])

get_domain (ZTmp, DomainTmp)

if (Index == 0)

copy_obj (DomainTmp, Domain, 1, 1)

else

concat_obj (Domain, DomainTmp, Domain)

endif

endfor

dev_display (Domain)

disp_message (WindowHandle, '3D Segmentation', 'window', 12, 12, 'black', 'true')

disp_message (WindowHandle, 'Segmented objects: ' + |ObjectModel3DOutID|, 'window', 40, 12, 'black', 'true')

disp_continue_message (WindowHandle, 'black', 'true')

stop ()

* Show the result of the fitting

dev_clear_window ()

* 外部函数

#dev_display_fitting_results (RegionCylinder, RegionSphere, RegionPlane, RegionNone, \

#                            ObjectModel3DOutID, WindowHandle, [])

* This procedure displays the results of a fitting operation.

* Additionally to the primitive regions, the radius of

* cylinders and spheres is displayed.

* The colors can be specified with the parameter Colors

* in the following manner:

* Color[0] is used for objects which could not be fitted

* Color[1] is used for cylinders

* Color[2] is used for spheres

* Color[3] is used for planes

*

Colors := ['dim gray','forest green','red','slate blue']

NumNone := 0

NumCylinders := 0

NumSpheres := 0

NumPlanes := 0

for Index := 0 to |ObjectModel3DOutID| - 1 by 1

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)

if (ParamValue == 'cylinder')

if (NumCylinders == 0)

copy_obj (DomainTmp, RegionCylinder, 1, -1)

RadiusCylinder := GenParamValuesP[6]

else

concat_obj (RegionCylinder, DomainTmp, RegionCylinder)

RadiusCylinder := [RadiusCylinder,GenParamValuesP[6]]

endif

NumCylinders := NumCylinders + 1

elseif (ParamValue == 'sphere')

if (NumSpheres == 0)

copy_obj (DomainTmp, RegionSphere, 1, -1)

RadiusSphere := GenParamValuesP[3]

else

concat_obj (RegionSphere, DomainTmp, RegionSphere)

RadiusSphere := [RadiusSphere,GenParamValuesP[3]]

endif

NumSpheres := NumSpheres + 1

else

if (NumPlanes == 0)

copy_obj (DomainTmp, RegionPlane, 1, -1)

else

concat_obj (RegionPlane, DomainTmp, RegionPlane)

endif

NumPlanes := NumPlanes + 1

endif

else

if (NumNone == 0)

copy_obj (DomainTmp, RegionNone, 1, -1)

else

concat_obj (RegionNone, DomainTmp, RegionNone)

endif

NumNone := NumNone + 1

endif

endfor

*

NumColors := |Colors|

if (NumNone > 0)

dev_set_color (Colors[0 % NumColors])

dev_display (RegionNone)

endif

if (NumCylinders > 0)

dev_set_color (Colors[1 % NumColors])

dev_display (RegionCylinder)

endif

if (NumSpheres > 0)

dev_set_color (Colors[2 % NumColors])

dev_display (RegionSphere)

endif

if (NumPlanes > 0)

dev_set_color (Colors[3 % NumColors])

dev_display (RegionPlane)

endif

disp_message (WindowHandle, '3D Fitting', 'window', -1, -1, 'black', 'true')

Message := 'Cylinders: ' + NumCylinders

Message[1] := 'Spheres: ' + NumSpheres

Message[2] := 'Planes: ' + NumPlanes

Message[3] := 'Undefined: ' + NumNone

disp_message (WindowHandle, Message, 'window', 40, 12, 'black', 'true')

if (NumCylinders > 0)

* Display radius for each cylinder

area_center (RegionCylinder, Area, Row, Column)

for Index := 0 to NumCylinders - 1 by 1

Radius := int(RadiusCylinder[Index] * 1000)

disp_message (WindowHandle, 'Cylinder\nr = ' + Radius + ' mm', 'image', Row[Index], Column[Index], 'white', 'false')

endfor

endif

if (NumSpheres > 0)

* Display radius for each cylinder sphere

area_center (RegionSphere, Area, Row, Column)

for Index := 0 to NumSpheres - 1 by 1

Radius := int(RadiusSphere[Index] * 1000)

disp_message (WindowHandle, 'Sphere\nr = ' + Radius + ' mm', 'image', Row[Index], Column[Index], 'white', 'false')

endfor

endif

* Example code, if further inspections should be made:

*

* Store only the data of the primitive to save memory

for Index := 0 to |ObjectModel3DOutID| - 1 by 1

* Copy only the data of the primitive

copy_object_model_3d (ObjectModel3DOutID[Index], 'primitives_all', CopiedObjectModel3DID)

* Clear the object model that is no longer used.

clear_object_model_3d (ObjectModel3DOutID[Index])

* Further inspections

* .....

* .....

* Clear the copied model after applying further inspections

clear_object_model_3d (CopiedObjectModel3DID)

endfor

dev_update_on ()

segment_object_model_3d的更多相关文章

随机推荐

  1. SGU 219 Synchrograph tarjian找环,理解题意,图论 难度:3

    http://acm.sgu.ru/problem.php?contest=0&problem=219 题目大意: 如果指向某个点的边权全都为正数,那么这个点就是可点燃的,点燃操作把入弧权值- ...

  2. 使用QQ邮箱SMTP服务的javamail配置

    最近做一个小项目要用到JAVA的邮箱的发送功能.遇到一些坑这里记录分享一下:QQ群交流:697028234 1.QQ邮箱一定要设置开通SMTP/POP这项.并生成授权码. 2.用MAVEN生成一个QU ...

  3. React Native入门指南

    转载自:http://www.jianshu.com/p/b88944250b25 前言 React Native 诞生于 2015 年,名副其实的富二代,主要使命是为父出征,与 Apple 和 Go ...

  4. python 库 Numpy 中如何求取向量范数 np.linalg.norm(求范数)(向量的第二范数为传统意义上的向量长度),(如何求取向量的单位向量)

    求取向量二范数,并求取单位向量(行向量计算) import numpy as np x=np.array([[0, 3, 4], [2, 6, 4]]) y=np.linalg.norm(x, axi ...

  5. 关于cookie和session的使用和理解

    由于项目需要,最近用session容器比较多,传载的同时加上了自己的一些理解,不足之处还请大家补充和纠正. 一.cookie机制和session机制的区别 ********************** ...

  6. java面试Linux常用命令使用方法大全

    1.# 表示权限用户(如:root),$ 表示普通用户   开机提示:Login:输入用户名   password:输入口令   用户是系统注册用户成功登陆后,可以进入相应的用户环境.   退出当前s ...

  7. 【idea】如何安装jetty容器,并使用。

    参考:https://www.jetbrains.com/idea/help/run-debug-configuration-jetty-server.html背景:web开发当中,我觉得服务层的代码 ...

  8. 【java基础】ThreadLocal的实现原理

    [一]:ThreadLocal对象的大体实现原理===>当前线程对象有一个ThreadLocal.ThreadLocalMap属性.===>声明的ThreadLocal对象最终存储在当前线 ...

  9. Documentation/filesystems/sysfs.txt 文档翻译--sysfs

    sysfs - 用于导出内核对象的文件系统. 1.sysfs是一个基于ram的文件系统,最初基于ramfs. 它提供了一种方法,可以将内核数据结构,它们的属性以及它们之间的链接导出到用户空间.sysf ...

  10. 转 How do GraphQL remote schemas work

    文章转自 prisma 官方博客,写的很不错 In this article, we want to understand how we can use any existing GraphQL AP ...