00. 目录

文章目录

  • 00. 目录
  • 01. 概述
  • 02. 签名
  • 03. 描述
  • 04. 注意
  • 05. 参数
  • 06. 结果
  • 07. 附录

01. 概述

for — 启动一个循环块,通常执行固定次数的迭代。

02. 签名

for( : : Start, End, Step : Index)

03. 描述

在HDevelop中的语法:for Index := Start to End by Step。

for语句启动一个通常是运行固定次数的迭代的循环分段。 for分段结束于相应的endfor语句。

迭代次数由Start值,End值和Step值共同决定。 所有这些参数都不一定是常量值,可以用表达式或变量初始化替代。 请注意,这些循环参数只被计算一次,即在for循环输入之前。 它们在循环之后不被重新计算,即在循环内对这些变量的任何修改都不会影响迭代次数。

传递的循环参数必须是整型或实型。 如果所有输入参数都是整数类型的,那么Index变量也是整型。 在所有其他情况下,Index变量将是real类型的。

在每次迭代开始时,将循环变量Index与End参数进行比较。 如果Step为正,则只要Index变量小于或等于End参数,就会运行for循环。 如果Step为负,则只要Index变量大于或等于End参数,就会执行for循环。

注意:如果将Step设置为real类型的值,则在Index变量预期与上一个周期中的End值完全匹配的情况下,可能会因为四舍五入误差而忽略最后一个循环。 因此,在一些系统中,下面的循环没有按照预期的那样运行了四次(Index变量设置为1.3,1.4,1.5和1.6),只运行了三次,因为在三次加法之后,索引变量由于四舍五入的误差而略大于1.6。

  I:=[]for Index := 1.3 to 1.6 by 0.1I := [I,Index]endfor

在循环内容的运行之后,即在到达相应的endfor语句或者continue语句之后,循环计数器Index的当前值会加上Step(在for循环的开始处被初始化)。 然后,如上所述重新判断循环条件。 根据结果,循环要么被重新运行,要么运行完毕。运行完毕时,将会继续运行相应的endfor语句之后的第一个语句。

循环中的存在break语句—没有被更多的内部分段所覆盖(that is not covered by a more internal block)—立即离开循环,并在相应的endfor语句之后继续运行。 与之相反的是,continue语句用于忽略当前循环中其余的循环内容,并继续执行索引变量并重新判断循环条件。

注意:在HALCON 11中,for循环相对于Index变量的行为发生了变化:在以前的版本中,循环体内的Index变量的变化被for语句忽略。 在判断循环条件之前,Index变量将被重置为一个内部计数器,计数器的计算公式如下:

Index := Start + count * Step

count是已经运行的循环次数。

使用HALCON 11之前的HALCON版本保存的程序和程序(program and procedure)在加载时通过分析它们的for循环保持不变地运行:如果在循环体内修改了这样的for循环的Index变量,则循环被设置为兼容模式并会进行相应的标注。所有以这种方式标记的循环都是使用旧的语义执行的,即在每个循环周期之前将Index变量重置为内部计数器以保持旧的行为。在程序列表中,for语句由一个警告三角形和行尾的标签__use_internal_index__标记。另外,在算子窗口中也会显示警告。check box允许取消所选for循环的兼容模式,并使用新的语义执行。在全文编辑器中删除标签__use_internal_index__具有相同的效果。但是,为了保持程序行为,必须通过将循环体开头的Index变量复制到局部变量来稍微调整for循环体。这个局部变量可以在循环体内随意使用和修改。

在任何情况下,建议避免在其内部修改for循环的Index变量,因为代码变得难以调试,代码将不兼容HALCON 11之前的HALCON版本。

如果for循环停止,例如通过停止语句或按下停止按钮,并且如果用户手动放置PC(程序计数器),则只要PC还在for循环内,for循环在当前迭代中继续或者跳到endfor语句。 如果PC放置在在for语句中(或之前)并再次执行,则循环将重新初始化并在开始时重新启动。

原文描述

Syntax in HDevelop: for Index := Start to End by Step

The for statement starts a loop block that is usually executed for a fixed number of iterations. The for block ends at the corresponding endfor statement.

The number of iterations is defined by the Start value, the End value, and the increment value Step. All of these parameters can be initialized with expressions or variables instead of constant values. Please note that these loop parameters are evaluated only once, namely, immediately before the for loop is entered. They are not re-evaluated after the loop cycles, i.e., any modifications of these variables within the loop body will have no influence on the number of iterations.

The passed loop parameters must be either of type integer or real. If all input parameters are of type integer, the Index variable will also be of type integer. In all other cases the Index variable will be of type real.

At the beginning of each iteration the loop variable Index is compared to the End parameter. If the increment value Step is positive, the for loop is executed as long as the Index variable is less than or equal to the End parameter. If the increment value Step is negative, the for loop is executed as long as the Index variable is greater than or equal to the End parameter.

Attention: If the increment value Step is set to a value of type real, it may happen that the last loop cycle is omitted owing to rounding errors in case the Index variable is expected to match the End value exactly in the last cycle. Hence, on some systems the following loop is not executed—as expected—for four times (with the Index variable set to 1.3, 1.4, 1.5, and 1.6), but only three times because after three additions the index variable is slightly greater than 1.6 due to rounding errors.

I:=[]
for Index := 1.3 to 1.6 by 0.1
I := [I,Index]
endfor
After the execution of the loop body, i.e., upon reaching the corresponding endfor statement or a continue statement, the increment value (as initialized at the beginning of the for loop) is added to the current value of the loop counter Index. Then, the loop condition is re-evaluated as described above. Depending on the result the loop is either executed again or finished in which case execution continues with the first statement after the corresponding endfor statement.

A break statement within the loop—that is not covered by a more internal block—leaves the loop immediately and execution continues after the corresponding endfor statement. In contrast, the continue statement is used to ignore the rest of the loop body in the current cycle and continue execution with adapting the Index variable and re-evaluating the loop condition.

Attention: The behavior of the for loop with respect to the Index variable has changed in HALCON 11: In previous versions changes to the Index variable within the loop body were ignored by the for statement. Before evaluating the loop condition the Index variable would be reset to an internal counter that was calculated by:

Index := Start + count * Step
where count was the number of already executed cycles.

Programs and procedures that were saved with a HALCON version prior to HALCON 11 are kept running unmodified by analyzing their for loops while loading: If the Index variable of such a for loop is modified within the loop body, the loop is set into a compatibility mode and marked accordingly. All for loops that are marked in such a way are executed using the old semantics, i.e., the Index variable is reset to the internal counter before each loop cycle to keep the old behavior. In the listing the for statement is marked by a warning triangle and the label use_internal_index at the end of the line. In addition, in the operator window a warning is displayed. A check box allows to cancel the compatibility mode for the selected for loop and perform it with the new semantics. Deleting the label use_internal_index in the full text editor has the same effect. However, to keep the program behavior, the body of the for loop must slightly be adapted by copying the Index variable at the begin of the loop body to a local variable. This local variable can be used and modified within the loop body at will.

In any case it is recommended to avoid modifying the Index variable of the for loop within its body because the code becomes harder to debug and the code will not be compatible to HALCON versions prior to HALCON 11.

If the for loop is stopped, e.g., by a stop statement or by pressing the Stop button, and if the PC is placed manually by the user, the for loop is continued at the current iteration as long as the PC remains within the for body or is set to the endfor statement. If the PC is set on the for statement (or before it) and executed again, the loop is reinitialized and restarts at the beginning.

04. 注意

05. 参数

Start (input_control)   number → (integer / real)
循环变量的起始值。
默认值: 1

End (input_control)    number → (integer / real)
循环变量的结束值。
默认值: 5

Step (input_control)    number → (integer / real)
循环变量的增量值。
默认值: 1

Index (output_control)    number → (integer / real)
循环变量

06. 结果

如果指定参数的值是正确的,for(作为算子)返回2(H_MSG_TRUE)。 否则,会引发异常并返回错误代码。

HDevelop例程

match_function_trans.hdev Calculate transformation parameters between two functions
fuzzy_measure_pin.hdev Measure pins of an IC using fuzzy measuring
for.hdev Use a for loop to iterate over extracted blobs
assign.hdev Assign values to variables and tuple elements

程序示例

read_image (Image, 'fabrik')
threshold (Image, Region, 128, 255)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
area_center (SelectedRegions, Area, Row, Column)
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
dev_display (SelectedRegions)
dev_set_color ('white')
for Index := 0 to |Area| - 1 by 1set_tposition (WindowHandle, Row[Index], Column[Index])write_string (WindowHandle, 'Area=' + Area[Index])
endfor

07. 附录

7.1 机器视觉博客汇总
网址:https://dengjin.blog.csdn.net/article/details/116837497

【机器视觉】 for算子相关推荐

  1. 机器视觉 边缘检测算子

    1.实验目的 利用opencv python实现对下图实现边缘检测算子. 2.实验过程 (1)在python安装opencv库, pip install opencv-python. (2)在pyth ...

  2. 拉普拉斯噪声公式_高斯拉普拉斯算子(Laplace of Gaussian)

    高斯拉普拉斯(Laplace of Gaussian) Laplace算子作为一种优秀的边缘检测算子,在边缘检测中得到了广泛的应用.该方法通过对图像 求图像的二阶倒数的零交叉点来实现边缘的检测,公式表 ...

  3. python 视觉技术_python+opencv实现机器视觉基础技术(边缘提取,图像滤波,边缘检测算子,投影,车牌字符分割)...

    机器视觉是人工智能正在快速发展的一个分支.简单说来,机器视觉就是用机器代替人眼来做测量和判断.它是一项综合技术,包括图像处理.机械工程技术.控制.电光源照明.光学成像.传感器.模拟与数字视频技术.计算 ...

  4. 【机器视觉】 write_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 write_measure - 将measure对 ...

  5. 【机器视觉】 translate_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 translate_measure - 转换一个m ...

  6. 【机器视觉】 set_fuzzy_measure_norm_pair算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 set_fuzzy_measure_norm_pa ...

  7. 【机器视觉】 set_fuzzy_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 set_fuzzy_measure - 指定一个模 ...

  8. 【机器视觉】 serialize_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 serialize_measure - 序列化me ...

  9. 【机器视觉】 reset_fuzzy_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 reset_fuzzy_measure - 重置一 ...

  10. 【机器视觉】 read_measure算子

    00. 目录 文章目录 00. 目录 01. 概述 02. 签名 03. 描述 04. 注意 05. 参数 06. 结果 07. 附录 01. 概述 read_measure - 从文件中读取一个me ...

最新文章

  1. Android与iOS对比
  2. flask 基础 宏的使用
  3. python爬虫图片-如何用Python来制作简单的爬虫,爬取到你想要的图片
  4. 计算机数据库技术的应用现状,数据库技术发展现状及趋势.doc
  5. [css] 你知道css的预处理器和后处理器都有哪些吗?它们有什么区别呢?
  6. pom.xml中添加阿里云Maven中央仓库配置
  7. android edittext 手机号码,Android中EditText中的电话号码格式
  8. 探讨如何确保对日软件外包开发过程中的质量
  9. java 基本语法都懂 ee_Java EE(一) 基础语法
  10. nginx php value,Nginx 设置 PHP_VALUE 的灵异问题
  11. python代码怎么样_python代码怎样清屏
  12. cad文字宽度因子_字体宽度因子改不了 cad宽度因子无法修改
  13. YDOOK: ANSYS Maxwell 19 教程20:Maxwell 2D Surface Approximation 网格划分
  14. html中如何写平方根等,开方符号 数学符号平方根号等怎么输入
  15. windows PC版微信双开
  16. 赚钱项目:1万粉丝的公众号,年赚15万!
  17. 安卓玩机搞机技巧综合资源---MIUI14全机型首版下载链接 刷机方法 获取root步骤【十二】
  18. Julia 安装,使用教程
  19. 架设个人Web服务器实战(通过ADSL路由)
  20. 十大开源项目_2014年十大开源项目

热门文章

  1. Linux对文件内容基本操作(学习笔记七)
  2. PHP学习:文件操作
  3. 提示JS错误:WebForm_PostBackOptions 未定义
  4. python如何离线安装第三方模块_扣丁学堂python开发之第三方模块pip离线安装
  5. 台式电脑怎么连接手机热点_电脑搜不到手机热点 为什么搜不到手机热点
  6. Java黑皮书课后题第3章:**3.9(商业:检验ISBN-10)ISBN-10由10个个位整数d1d2d3d4d5d6d7d8d9d10组成,最后一位d10是校验和,输入前9个数,显示10位ISBN
  7. Linux 内核 up down,信号量机制中的DOWN操作与UP操作详解
  8. whiel oracle,Oracle中的for和while循环
  9. Queue+Stack(C++,标准库中的队列和栈)
  10. poj - 3254 Corn Fields (状态压缩dp入门)