机器视觉 dev_open_window算子
Posted 沧海一笑-dj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器视觉 dev_open_window算子相关的知识,希望对你有一定的参考价值。
00. 目录
01. 概述
dev_open_window - 打开一个新的图形窗口。
02. 签名
dev_open_window( : : Row, Column, Width, Height, Background : WindowHandle)
03. 描述
dev_open_window 打开一个新的图形窗口,可用于显示图像、区域和线条等标志性对象以及执行文本输出。 此窗口自动变为活动状态,这意味着所有输出(dev_display 和操作员结果的自动显示)都重定向到此窗口。 这由活动按钮上的发光灯显示。
标准HALCON显示,绘图,鼠标,文本输出和可视化参数算子(如disp_image,disp_region,draw_circle,get_mbutton,write_string,set_rgb等)需要在参数WindowHandle中返回的逻辑窗口号,它显示在图形窗口的标题栏。
Background中指定的颜色为创建的窗口背景颜色。 该参数不适用于算子open_window。 在那里,需要通过预先调用set_window_attr(::‘background_color’,Background :)可以实现相同的行为。
关闭图形窗口可以通过按下窗口框的关闭按钮或通过可视化菜单,或者通过调用dev_close_window。
图形窗口的原点是坐标为(0,0)的左上角。 x值(column)从左到右增加,y值(row)从上到下增加。 默认情况下,坐标系的设置方式是在不剪切图像的情况下显示图像,并完全适合图形窗口。 对于在程序重置或新程序加载之后显示的第一图像,或者如果当前图像具有与之前显示的图像不同的图像大小,根据此规则,坐标系会适应于窗口大小。 窗口的大小不会自动调整,因此,如果图像的宽高比与窗口的长宽比不同,则图像会变形以适合窗口。 这可以通过“窗口大小”菜单进行更改。
通过滚动鼠标滚轮,使用“移动”或“缩放”模式,通过“图像大小”菜单,借助“可视化参数”对话框上的“缩放”选项卡或使用操作符dev_set_part,可以交互式更改可见图像部分。
每个图形窗口都有一个历史记录,包含:
objects
显示参数
历史记录会记录从最近的清除动作或显示全图像以来已经显示或改变了的图形。 如果窗口的重绘被触发,例如在改变窗口尺寸之后,为了重建完整的窗口内容会利用历史记录。 其他使用HALCON算子(如disp_image或disp_region,text(write_string)或geometric对象(disp_line,disp_circle等))显示的图形输出不是历史记录的一部分,因此不能重绘。 只有使用HDevelop操作符dev_display或HDevelop操作(如双击图标)显示的对象类image,region和XLD才是历史记录的一部分。
按清空按钮清除图形窗口的内容和窗口的历史。 这也可以通过使用算子dev_clear_window来实现。 这不会影响当前的显示参数。
图形窗口的大小可以通过用鼠标拖动窗口边界交互地改变。 此外,可以通过“窗口大小”菜单将窗口大小调整为图像大小(或其一部分或它的多倍)。 之后,使用与以前相同的可视部分自动重新显示窗口内容(Afterwards, the window content is redisplayed automatically using the same visible part as before.)。
图形窗口的显示参数可以通过其context menu,可视化菜单,可视化参数对话框或适当的HDevelop算子(如dev_set_color,dev_set_line_width,dev_set_draw)来指定。 根据“立即应用”首选项,参数更改将应用于最后显示的对象,或者从现在开始应用于所有后续对象。 与标准的HALCON窗口算子相反,新的设置也用于所有新的图形窗口。
有关HALCON窗口的更多底层信息,请参见“HDevelop Reference Manual”以及“HDevelop用户指南”的Graphical User Interface -> Graphics Window一章。
原文描述:
dev_open_window opens a new graphics window, which can be used to display iconic objects like images, regions, and lines as well as to perform textual output. This window automatically becomes active, which means that all output (dev_display and automatic display of operator results) is redirected to this window. This is shown by the lucent lamp on the Active button.
The standard HALCON display, drawing, mouse, text output, and visualization parameter operators (like disp_image, disp_region, draw_circle, get_mbutton, write_string, set_rgb, etc.) need the logical window number that is returned in the parameter WindowHandle and displayed in the title bar of the graphics window.
The background of the created window is set to the color specified in Background. This parameter is not available for the operator open_window. There, the same behavior can be achieved by calling set_window_attr(::‘background_color’,Background:) in advance.
The graphics window is closed by pressing the Close button of the window frame, via the Visualization menu, or by calling dev_close_window.
The origin of the graphics window is the upper left corner with the coordinates (0,0). The x values (columns) increase from left to right, the y values (rows) increase from top to bottom. As a default, the coordinate system is set in a way that images are displayed without clipping and fitting completely into the graphics window. The coordinate system is adapted to the windows size according to this rule for the first image that is displayed after a program reset or the loading of a new program or if the current image has a different image size than the image that was displayed before. The size of the window is not adapted automatically, hence, if the aspect ratio of the image differs from that of the window, the image is distorted to fit into the window. This can be changed via the Window Size menu.
The visible image part can be changed interactively by spinning the mouse wheel, using the Move or Zoom mode, via the Image Size menu, with the help of the Zoom tab card on the Visualization Parameters dialog, or with the operator dev_set_part.
Each graphics window manages a history which contains the
objects and display parameters
which have been displayed or changed since the most recent clear action or display of a full image. This history is used if a redraw of the window is triggered, e.g., after a change of the windows size, in order to reconstruct the complete window contents. Other iconic output that was displayed using HALCON operators like disp_image or disp_region, text (write_string), or geometric objects (disp_line, disp_circle, etc.) are not part of the history, and can therefore not be redrawn. Only the object classes image, region, and XLD that are displayed with the HDevelop operator dev_display or by HDevelop actions like double clicking on an icon are part of the history.
Pressing the Clear button clears the graphics window contents and the history of the window. This can also be achieved by using the operator dev_clear_window. This will not effect the current display parameters.
The size of the graphics window can be changed interactively by dragging the window border with the mouse. Furthermore, it is possible to adapt the window size to the image size (or a part or multiple of it) via the Window Size menu. Afterwards, the window content is redisplayed automatically using the same visible part as before.
The display parameters of the graphics window can be specified via its context menu, the Visualization menu, the Visualization Parameters dialog, or the appropriate HDevelop operators like dev_set_color, dev_set_line_width, dev_set_draw. Depending on the Apply Immediately preference, the parameter changes are applied to the lastly displayed object or apply from now on for all following objects. In contrast to the standard HALCON window operators, the new settings are also used for all new graphics windows.
Additional information about the underlying HALCON window can be found at open_window and about the HDevelop graphics window in the “HDevelop Reference Manual” chapter Graphical User Interface -> Graphics Window as well as in the “HDevelop User’s Guide”.
04. 注意
使用HDevelop的代码导出功能,为该算子生成的代码可能与相关的HALCON算子具有不同的行为。 有关将HDevelop图形算子导出为不同编程语言的代码的详细说明,请参阅“HDevelop User’s Guide”中的 Code Export -> General Aspects of Code Generation -> Graphics Windows一章。
05. 参数
Row (input_control) rectangle.origin.y → (integer)
Row index of upper left corner.
Default value: 0
Typical range of values: 0 ≤ Row
Minimum increment: 1
Recommended increment: 1
Restriction: Row >= 0
Column (input_control) rectangle.origin.x → (integer)
Column index of upper left corner.
Default value: 0
Typical range of values: 0 ≤ Column
Minimum increment: 1
Recommended increment: 1
Restriction: Column >= 0
Width (input_control) rectangle.extent.x → (integer)
Width of the window.
Default value: 256
Typical range of values: 0 ≤ Width
Minimum increment: 1
Recommended increment: 1
Restriction: (Width > 0) || (Width == -1)
Height (input_control) rectangle.extent.y → (integer)
Height of the window.
Default value: 256
Typical range of values: 0 ≤ Height
Minimum increment: 1
Recommended increment: 1
Restriction: (Height > 0) || (Height == -1)
Background (input_control) integer → (integer / string)
Color of the background of the new window.
Default value: ‘black’
WindowHandle (output_control) window → (integer)
Window identifier.
HDevelop例程
stamp_catalogue.hdev Segment and group characters on a cluttered page
measure_screw.hdev Measure several features of a screw
fit_ellipse_tooth_rim_xld.hdev Approximate the contour of a tooth rim with an ellipse to find its center
find_pads.hdev Find pads on a die
display_operators.hdev Visualize results
dev_open_window.hdev Open graphics windows in HDevelop
dev_close_window.hdev Close graphics windows in HDevelop
critical_points_sub_pix.hdev Detect critical points with subpixel accuracy
clip_contours_xld.hdev Clip an XLD contour
advanced_visualization_settings.hdev Improve the visualization with transparency, anti-aliasing, and more
程序示例
dev_close_window ()
read_image (For5, 'for5')
get_image_size (For5, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (For5)
dev_set_lut ('rainbow')
dev_display (For5)
stop ()
dev_set_lut ('default')
dev_display (For5)
stop ()
dev_set_part (100, 100, 300, 300)
dev_display (For5)
06. 结果
如果指定参数的值正确,则dev_open_window返回2(H_MSG_TRUE)。 否则会引发异常并返回错误代码。
07. 附录
7.1 机器视觉博客汇总
网址:https://dengjin.blog.csdn.net/article/details/116837497
以上是关于机器视觉 dev_open_window算子的主要内容,如果未能解决你的问题,请参考以下文章