1、可用算子
在Halcon机器视觉软件中,提供了一系列用于创建不同类型绘图对象的算子,这些算子允许用户在图像上绘制各种形状,并用于后续的图像处理任务。以下是您提到的几个Halcon算子的介绍:
-
create_drawing_object_circle_sector
- 功能:创建一个圆弧扇形绘图对象。
- 参数:通常包括圆心的坐标、起始角度、终止角度、半径等,用于定义圆弧扇形的位置和形状。
- 应用:可以用于标记图像中的特定扇形区域,或作为交互式工具的一部分。
-
create_drawing_object_rectangle1
- 功能:创建一个矩形绘图对象。
- 参数:通常包括矩形的一个顶点坐标和矩形的宽度、高度,或者对角线的两个点坐标。
- 应用:常用于标记图像中的矩形区域,如感兴趣区域(ROI)的定义。
-
create_drawing_object_rectangle2
- 功能:与create_drawing_object_rectangle1类似,但可能提供不同的参数设置或更灵活的矩形定义方式。
- 参数:可能包括矩形的中心点坐标、宽度、高度以及旋转角度等。
- 应用:同样用于标记图像中的矩形区域,但提供了更多的灵活性。
-
create_drawing_object_ellipse
- 功能:创建一个椭圆绘图对象。
- 参数:通常包括椭圆中心点的坐标、长轴和短轴的半径,以及可能的旋转角度。
- 应用:用于标记图像中的椭圆区域,或作为图像分析中的参考形状。
-
create_drawing_object_circle
- 功能:创建一个圆形绘图对象。
- 参数:通常包括圆心的坐标和圆的半径。
- 应用:常用于标记图像中的圆形区域,如圆形目标的检测与识别。
-
create_drawing_object_ellipse_sector
- 功能:创建一个椭圆扇形绘图对象。
- 参数:通常包括椭圆中心的坐标、长轴和短轴的半径、起始角度、终止角度等。
- 应用:用于标记图像中的特定椭圆扇形区域,或作为交互式工具的一部分。
-
create_drawing_object_xld
- 功能:创建一个基于扩展线描述(XLD)的绘图对象。
- 参数:通常包括XLD数据,这些数据描述了图像的轮廓或多边形。
- 应用:用于标记图像中的复杂形状或轮廓,如边缘检测、轮廓提取等任务的结果。
-
create_drawing_object_line
- 功能:创建一个直线绘图对象。
- 参数:通常包括直线的起点和终点坐标,或者直线的方向、长度和位置参数。
- 应用:常用于标记图像中的直线特征,如道路边缘、建筑物轮廓等。
这些算子在Halcon的图像处理和分析中发挥着重要作用,它们允许用户以直观的方式在图像上绘制各种形状,并作为后续图像处理任务的参考或输入。通过结合使用这些算子和Halcon的其他功能,可以实现复杂的图像处理和分析任务。
2、示例代码
* 这个示例展示了如何在一个交互式边缘检测应用中使用类型为“circle_arc”(圆弧)的绘图对象。
* 在交互式地移动、调整大小或更改绘图对象的角度时,会应用一个过滤器来检测绘图对象所包围区域内的边缘。
* 与其他绘图操作符(例如draw_circle)相比,使用绘图对象不会阻塞整个应用程序。
* 因此,用户可以在不先结束交互的情况下与对象进行交互或对程序进行修改。
* Initialize settings
dev_update_off ()
dev_close_window ()
*
dev_set_preferences ('graphics_window_context_menu', 'false')
* Read image
read_image (Image, 'mreut')
get_image_size (Image, Width, Height)
get_system ('operating_system', OS)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_color ('green')
dev_display (Image)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* Display short description
Message := 'This example shows how to apply a Sobel filter'
Message[1] := 'within the area of a drawing object of type'
Message[2] := '\'circle_arc\' to detect edges while'
Message[3] := 'interactively moving, resizing, or changing'
Message[4] := 'the angle of the circle sector.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
*
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* Create a drawing object of type 'circle_arc' and set its color
* 创建一个类型为“circle_arc”(圆弧)的绘图对象并设置其颜色
create_drawing_object_circle_sector (250, 200, 100, 0, 3.14159, DrawID)
set_drawing_object_params (DrawID, 'color', 'yellow')
*
* Attach the drawing object and the image to the window
* 将绘图对象和图像附加到窗口
attach_drawing_object_to_window (WindowHandle, DrawID)
attach_background_to_window (Image, WindowHandle)
*
* Display a short description using a text drawing object
* 使用文本绘图对象显示简短描述
Message := 'Move, resize or change the angles by dragging\nthe handles and border of the circle sector.\nExit the interaction by clicking the right\nmouse button.'
get_font (WindowHandle, Font)
create_drawing_object_text (12, 20, Message, DrawIDMessage)
set_drawing_object_params (DrawIDMessage, ['color', 'font'], ['yellow',Font])
attach_drawing_object_to_window (WindowHandle, DrawIDMessage)
*
* Detect edges interactively using the drawing object
* ***************************************************
* Apply a sobel filter in the area of the drawing object to
* extract edges. The circle sector can be moved, resized, or
* changed interactively by the user. The edges are detected
* constantly while the drawing object is adjusted.
* The user interaction is ended by clicking the right mouse button.
* 使用绘图对象交互式地检测边缘
* 在绘图对象所在的区域内应用Sobel滤波器以提取边缘。
* 用户可以交互式地移动、调整大小或更改圆弧扇形。在调整绘图对象时,会不断检测边缘。
* 通过点击鼠标右键来结束用户交互。
set_window_param (WindowHandle, 'flush', 'false')
Button := 0
while (Button != 4)
try
image_processing (Image, EdgeAmplitude, DrawID)
display_results (EdgeAmplitude, WindowHandle)
* Check the mouse position and button
* 检查鼠标位置和按钮
get_mposition (WindowHandle, Row, Column, Button)
catch (Exception)
* Keep waiting until the mouse is positioned over the image
* 一直等待,直到鼠标移动到图像上方
endtry
endwhile
set_window_param (WindowHandle, 'flush', 'true')
*
* Detach the drawing objects
detach_drawing_object_from_window (WindowHandle, DrawID)
detach_drawing_object_from_window (WindowHandle, DrawIDMessage)
detach_background_from_window (WindowHandle)
*
* Clear the drawing objects
clear_drawing_object (DrawID)
clear_drawing_object (DrawIDMessage)
*
dev_clear_window ()
dev_display (Image)
disp_message (WindowHandle, 'The drawing object has been cleared.', 'window', 12, 12, 'black', 'true')
3、示例演示
交互修改的区域