00. 目录

 

 

01. 概述

dev_disp_text — 在当前图形窗口中显示文本。

02. 签名

dev_disp_text( : : String, CoordSystem, Row, Column, Color, GenParamName, GenParamValue : )

03. 描述

dev_disp_text 在当前图形窗口的位置 (Row,Column) 显示文本。

如果只定义了一个位置,则为 String 的每个元素显示一个文本行。 此外, ‘\n’ 将被解释为换行符,即执行换行符。

如果定义了多个位置,String 中只允许单个字符串或每个位置一个字符串。 在这种情况下,必须使用 ‘\n’ 强制换行。

String 末尾的换行符 (’\n’) 将被忽略。

文本的位置可以在窗口坐标 (CoordSystem = ‘window’) 或图像坐标 (CoordSystem = ‘image’) 中指定,这在使用缩放图像时很有用。

除了提供 (Row,Column) 坐标外,还可以将预定义的值传递给 Row 和 Column 以在窗口中的固定位置显示文本(仅当 CoordSystem = ‘window’ 时):

‘top’, ‘left’ ‘top’, ‘center’ ‘top’, ‘right’
‘center’, ‘left’ ‘center’, ‘center’ ‘center’, ‘right’
‘bottom’, ‘left’ ‘bottom’, ‘center’ ‘bottom’, ‘right’

参数 Color 也接受值的元组。 在这种情况下,如果使用单个位置,则为每个新文本位置或每个新文本行循环使用指定的颜色。

通用参数

disp_text 可以在框中显示字符串(默认)。 此行为和框的外观由 GenParamName 和 GenParamValue 中的通用参数定义。

'box'
If 'box' is set to 'true', the text is written within a box. The look of the box and its optional shadow can be configured with the generic parameters below.

possible values: 'true' and 'false'

default value: 'true'

'box_color'
Sets the color of the box.

possible values: a string containing the color name (e.g. 'white', 'red', or '#aa00bba0')

default value: '#fce9d4' (which is a light orange)

'shadow'
If 'shadow' is set to 'true', an additional shadow is displayed beneath the box (if 'box' is 'true').

possible values: 'true' and 'false'

default value: 'true' if 'box_color' is set to a color without alpha value, 'false' otherwise

'shadow_color'
Sets the color of the shadow if 'shadow' is 'true'.

possible values: a string containing the color name (e.g. 'black', 'red', or '#aa00bba0')

default value: '#f28d26' (which is a darker orange) if 'box_color' is not set, 'white' otherwise

'border_radius'
Controls the roundness of the box's corners. For sharp corners set it to 0, for smoother corners to higher values.

possible values: positive real numbers or 0

default value: 2

'box_padding'
Controls to which amount in pixels the box is extended around the text.

possible values: positive real number

default value: 0

'shadow_sigma'
Controls to which amount the shadow beneath the box is blurred. Set it to 0 for a sharp shadow.

possible values: positive real number or 0

default value: 1.5

'shadow_dx' and 'shadow_dy'
Controls the offset of the shadow in column ('shadow_dx') and row ('shadow_dy') direction in pixels.

possible values: any real number

default_value: 2

原文描述

dev_disp_text displays text in the current graphics window at the position (Row,Column).

If only a single position is defined, one text line is displayed for each element of String. Also, ‘\n’ will be interpreted as a newline character, i.e., a line break is performed.

If multiple positions are defined, only a single string or one string for each position is allowed in String. In this case, line breaks have to be forced with ‘\n’.

Newlines (’\n’) at the end of String are ignored.

The position of the text may be specified in window coordinates (CoordSystem = ‘window’) or in image coordinates (CoordSystem = ‘image’), which is useful when using zoomed images.

In addition to supplying (Row,Column) coordinates, it is also possible to pass predefined values to Row and Column to display the text at a fixed position in the window (only if CoordSystem = ‘window’).:

‘top’, ‘left’ ‘top’, ‘center’ ‘top’, ‘right’
‘center’, ‘left’ ‘center’, ‘center’ ‘center’, ‘right’
‘bottom’, ‘left’ ‘bottom’, ‘center’ ‘bottom’, ‘right’

The parameter Color also accepts tuples of values. In that case, the specified colors are used cyclically for every new text position or for every new line of text if a single position is used.

Generic Parameters

disp_text may display the String within a box (default). This behavior and the look of the box are defined with the generic parameters in GenParamName and GenParamValue.

‘box’
If ‘box’ is set to ‘true’, the text is written within a box. The look of the box and its optional shadow can be configured with the generic parameters below.

possible values: ‘true’ and ‘false’

default value: ‘true’

‘box_color’
Sets the color of the box.

possible values: a string containing the color name (e.g. ‘white’, ‘red’, or ‘#aa00bba0’)

default value: ‘#fce9d4’ (which is a light orange)

‘shadow’
If ‘shadow’ is set to ‘true’, an additional shadow is displayed beneath the box (if ‘box’ is ‘true’).

possible values: ‘true’ and ‘false’

default value: ‘true’ if ‘box_color’ is set to a color without alpha value, ‘false’ otherwise

‘shadow_color’
Sets the color of the shadow if ‘shadow’ is ‘true’.

possible values: a string containing the color name (e.g. ‘black’, ‘red’, or ‘#aa00bba0’)

default value: ‘#f28d26’ (which is a darker orange) if ‘box_color’ is not set, ‘white’ otherwise

‘border_radius’
Controls the roundness of the box’s corners. For sharp corners set it to 0, for smoother corners to higher values.

possible values: positive real numbers or 0

default value: 2

‘box_padding’
Controls to which amount in pixels the box is extended around the text.

possible values: positive real number

default value: 0

‘shadow_sigma’
Controls to which amount the shadow beneath the box is blurred. Set it to 0 for a sharp shadow.

possible values: positive real number or 0

default value: 1.5

‘shadow_dx’ and ‘shadow_dy’
Controls the offset of the shadow in column (‘shadow_dx’) and row (‘shadow_dy’) direction in pixels.

possible values: any real number

default_value: 2

04. 注意

使用HDevelop的代码导出功能,为该算子生成的代码可能与相关的HALCON算子具有不同的行为。 有关将HDevelop图形算子导出为不同编程语言的代码的详细说明,请参阅“HDevelop User’s Guide” 中的Code Export -> General Aspects of Code Generation -> Graphics Windows一章。

05. 参数

String (input_control) string(-array) → (string)
A tuple of strings containing the text message to be displayed. Each value of the tuple will be displayed in a single line.

Default value: ‘hello’

CoordSystem (input_control) string → (string)
If set to ‘window’, the text position is given with respect to the window coordinate system. If set to ‘image’, image coordinates are used (this may be useful in zoomed images).

Default value: ‘window’
List of values: ‘image’, ‘window’

Row (input_control) point.y(-array) → (integer / real / string)
The vertical text alignment or the row coordinate of the desired text position.

Default value: 12

List of values: 12, ‘bottom’, ‘center’, ‘top’

Column (input_control) point.x(-array) → (integer / real / string)
The horizontal text alignment or the column coordinate of the desired text position.

Default value: 12

List of values: 12, ‘center’, ‘left’, ‘right’

Color (input_control) string(-array) → (string)
A tuple of strings defining the colors of the texts.

Default value: ‘black’
List of values: ‘black’, ‘blue’, ‘coral’, ‘cyan’, ‘forest green’, ‘green’, ‘lime green’, ‘magenta’, ‘red’, ‘slate blue’, ‘yellow’

GenParamName (input_control) attribute.name(-array) → (string)
Generic parameter names.

Default value: []

List of values: ‘border_radius’, ‘box’, ‘box_color’, ‘box_padding’, ‘shadow’, ‘shadow_color’, ‘shadow_dx’, ‘shadow_dy’, ‘shadow_sigma’

GenParamValue (input_control) attribute.value(-array) → (string / integer / real)
Generic parameter values.

Default value: []

List of values: 5.0, ‘black’, ‘blue’, ‘false’, ‘forest green’, ‘red’, ‘true’, ‘white’

06. 结果

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

HDevelop例程

reconstruct_surface_stereo_pairwise_workflow.hdev Explain how to reconstruct a 3D object model with multi-view stereo using the ‘surface_pairwise’ method
reconstruct_surface_stereo_fusion_workflow.hdev Explain how to reconstruct a 3D object model with multi-view stereo using the ‘surface_fusion’ method
reconstruct_surface_stereo_fusion.hdev Reconstruct a 3D object model with multi-view stereo using the ‘surface_fusion’ method
dev_disp_text.hdev Explain the usage of dev_disp_text and its generic parameters
advanced_visualization_settings.hdev Improve the visualization with transparency, anti-aliasing, and more

程序示例

dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_disp_text ('Display some text in a box', 'window', 12, 12, \
               'black', [], [])

07. 附录

7.1 机器视觉博客汇总