segment_object_model_3d
* ***********************************************************************
* 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的更多相关文章
随机推荐
- 在EORow或者VORow中对数据进行重复性校验
需求:在设置付款条件时不允许账期+付款方式重复. 由于本次需求仅需要对VO缓存中的数据进行重复性校验,所以仅需进行缓存遍历即可,不需要校验数据库. 方式1,在EORow的进行数据校验. public ...
- 【Python】重载模块
命令窗口中调试代码,往往需要重载模块已进行最新的代码调试. 主要有两种方式: 1. Python shell 窗口 reload(module) 2. ipython 窗口 %load_ext aut ...
- asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
上文件传很常见,现在就文件上传利用HTML的File控件(uploadify)的,这里为大家介绍一下(uploadify)的一些使用方法.在目前Web开发中用的比较多的,可能uploadify(参考h ...
- CF86D
题解: 莫队分块 分块大小为sqrt(n) 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ll; ...
- Sonar在ant工程中读取单元测试和覆盖率报告
虽然sonar支持ant工程的构建,但目前最大的不足是无法在分析过程中产生单元测试和覆盖率报告,这样在sonar面板上覆盖率板块就始终没有数据.但幸运的是,sonar可以读取已经生成好的报告,让报告的 ...
- pshell远程连接服务器
在页面添加ip 和 端口 还有 用户,我这里填的是服务器root用户 成功之后 端口后是可以改的 首先看下ssh是否启动 rpm -qa | grep ssh 有的话就是vi /etc/ ...
- Yii 初识
接管一个Yii的系统,因为没有文档,所以非常上火. 01 查版本 Yii::getVersion(); 02 生成webapp Yii 是支持通过命令行生成webapp的.其中, yiic.bat是W ...
- HDU 1358
http://acm.hdu.edu.cn/showproblem.php?pid=1358 求某个前缀的周期,用Next求循环节的题目 #include <iostream> #incl ...
- ZetCode PyQt4 tutorial Drag and Drop
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...
- kubernetes下的Nginx加Tomcat三部曲之三:实战扩容和升级
本章是<kubernetes下的Nginx加Tomcat三部曲系列>的终篇,今天咱们一起在kubernetes环境对下图中tomcat的数量进行调整,再修改tomcat中web工程的源码, ...