日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【机器视觉】 for算子

發布時間:2024/4/24 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【机器视觉】 for算子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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算子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。