[machine vision] HDevelop language foundation - container and reserved words

Posted by amylou on Sun, 30 Jan 2022 16:25:16 +0100

00. Contents

01. Reserved words

The identifiers listed in table 8.25 are reserved words, and their use is strictly limited to their predefined meanings. They cannot be used as variable names.

02. Vessel overview

Vector is a container that can hold any number of elements. All elements must have exactly the same variable type (i.e. tuple, icon object or vector). Variables of type vector are unique to HDevelop. It is available in HDevelop 12.0 or later. Note that you cannot use the vector variable in older versions of HDevelop programs.

The Vector of a tuple or object is called one-dimensional, the Vector of a tuple or object is called two-dimensional, and so on. The type of Vector cannot be changed in the program, that is, its dimension must remain unchanged, and the Vector of tuple cannot be assigned icon object, and vice versa.

This is the definition of Vector in EBNF (extended Bakos Noel form) syntax:

vector = "{" list "}" ;
list = tuplelist | objectlist | vectorlist ;
tuplelist = tuple, {",", tuple} ;
objectlist = object, {",", object} ;
vectorlist = vector, {",", vector} ;
tuple = "[" control "]" ;
control = string | integer | real | boolean ;

03. Construction vessel

Vector is defined by providing a comma separated list of elements in braces.

vectorT := {[1], [2], [3]} // one-dimensional vector
This is equivalent to:
vectorT := {1, 2, 3} // tuples of length 1 do not require square brackets

*Of course, variable names or arbitrary expressions can be used instead of constants.
t1 := 1
vectorT := {t1, t1 * 2, 3}

The following example defines a container for an icon object.

read_image (Image, 'clip')
threshold (Image, Region, 0, 63)
connection (Region, ConnectedRegions)
vectorO := {Image, Region, ConnectedRegions}

The following example defines a two-dimensional container variable.

vectorV := {vectorT, {[4,5,6,7], [8,9]}}

It can also be used at() and The insert() operation defines container variables (see below).

The list of container elements may also be empty, that is, empty Vector {} is valid, as shown in the following example:

vectorV2 := {{1,2}, {}}

Note, however, that empty containers have no specific type. Therefore, all three of the following null assignments are valid:

vectorO2 := vectorO
vectorT2 := vectorT
vectorV2 := vectorV
vectorO2 := {}
vectorT2 := {}
vectorV2 := {}

Assigning an empty container to a vector variable is equivalent to Clear operation (see below). On the other hand, this means that assigning an empty container to a variable is not sufficient to define the type of variable (see the section "variable types" on page 276). Such a variable will have an undefined type (and therefore invalid) unless its type is correctly defined elsewhere in the program.

04. Container element operation

use. The at() operation accesses a single container element, and its parameters range from 0 to the number of container elements minus 1. Multiple can be combined The at() operation to access the child elements of the multidimensional container. Accessing a container element that does not exist is a runtime error.

tuple := vectorT.at(0) // tuple := 1
region := vectorO.at(1) // region := Region
vector := vectorV.at(0) // vector := {[1,2,3]}
tuple := vectorV.at(1).at(1) // tuple := [8, 9]

The. at() operation is also used to set the container element. Writing to non-existent container elements is allowed. If necessary, the container automatically fills with empty elements.

vectorT.at(2) := 33 // vectorT := {[1], [2], [33]}
vectorE.at(4) := 'text' // vectorE := {[], [], [], [], 'text'}

The at() operation also allows the container to be constructed dynamically in the loop:

for i:= 0 to 5 by 1
vecT.at(i) := gen_tuple_const(i,5)
endfor

The. insert() operation inserts a value at a specified index position. It moves the value from the given index to the last position and sets the value at the index to the new value.

The. remove() operation does the opposite. It deletes the value at the specified location and moves all subsequent values to the left.

vectorT.insert(1, 99) // vectorT := {[1], [99], [2], [33]}
vectorT.remove(2) // vectorT := {[1], [99], [33]}

And Like the at() operation, the vector will automatically fill in empty elements if necessary.

vectorNew.insert(2, 3) // vectorNew := {[], [], [3]}

. concat() connects two containers of the same type and dimension.

vectorC := vectorT.concat(vectorNew) // vectorC := {[1], [99], [33], [], [], [3]}

Gets the number of container elements

Use the length() operation to query the number of container elements.

i := vectorT.length() // i := 3
j := vectorV.length() // j := 2
k := vectorV.at(0).length() // k := 3

Clear elements in container

The. clear() operation deletes all elements from the corresponding container. Note, however, that the cleared container still retains its variable type.

vectorT.clear()
* vectorT := vectorO // illegal: vectorT is a tuple vector
* vectorT := vectorV // illegal: vectorT is one-dimensional

Modifying elements in a container

.clear(),. insert() and The special thing about remove() operations is that they modify the input container.
Therefore, they can only be used in independent program statements (so-called executable expressions), not in expressions that assign or input parameters. However, it is allowed to connect multiple modification container operations in one executable expression, for example:

v := {1, 2, 3}
v.insert(1, 5).insert(2, 4).remove(0) // sets v to {5, 4, 2, 3}

Using executable_ The expression special operator modifies the container in the operator window input.

Test the (inequality) of container variables

==And= Operators are used to test whether two container variables are equal or unequal.

Convert vectors to tuples and vice versa

You can use the operator convert_vector_to_tuple converts variables in the container into tuples.

convert_vector_to_tuple (vectorV, T) // T := [1, 2, 3, 4, 5, 6, 7, 8, 9]

You can use the operator convert_tuple_to_vector_1 convert elements in tuples into containers

convert_tuple_to_vector_1d (T, 1, V) // V := {[1],[2],[3],[4],[5],[6],[7],[8],[9]}

05. Reserved

06. Appendix

6.1 machine vision blog summary
website: https://dengjin.blog.csdn.net/article/details/116837497

Topics: Container Halcon machine vision