【Halcon】创建一个可交互修改的区域

1、可用算子

        在Halcon机器视觉软件中,提供了一系列用于创建不同类型绘图对象的算子,这些算子允许用户在图像上绘制各种形状,并用于后续的图像处理任务。以下是您提到的几个Halcon算子的介绍:

  1. create_drawing_object_circle_sector

    • 功能:创建一个圆弧扇形绘图对象。
    • 参数:通常包括圆心的坐标、起始角度、终止角度、半径等,用于定义圆弧扇形的位置和形状。
    • 应用:可以用于标记图像中的特定扇形区域,或作为交互式工具的一部分。
  2. create_drawing_object_rectangle1

    • 功能:创建一个矩形绘图对象。
    • 参数:通常包括矩形的一个顶点坐标和矩形的宽度、高度,或者对角线的两个点坐标。
    • 应用:常用于标记图像中的矩形区域,如感兴趣区域(ROI)的定义。
  3. create_drawing_object_rectangle2

    • 功能:与create_drawing_object_rectangle1类似,但可能提供不同的参数设置或更灵活的矩形定义方式。
    • 参数:可能包括矩形的中心点坐标、宽度、高度以及旋转角度等。
    • 应用:同样用于标记图像中的矩形区域,但提供了更多的灵活性。
  4. create_drawing_object_ellipse

    • 功能:创建一个椭圆绘图对象。
    • 参数:通常包括椭圆中心点的坐标、长轴和短轴的半径,以及可能的旋转角度。
    • 应用:用于标记图像中的椭圆区域,或作为图像分析中的参考形状。
  5. create_drawing_object_circle

    • 功能:创建一个圆形绘图对象。
    • 参数:通常包括圆心的坐标和圆的半径。
    • 应用:常用于标记图像中的圆形区域,如圆形目标的检测与识别。
  6. create_drawing_object_ellipse_sector

    • 功能:创建一个椭圆扇形绘图对象。
    • 参数:通常包括椭圆中心的坐标、长轴和短轴的半径、起始角度、终止角度等。
    • 应用:用于标记图像中的特定椭圆扇形区域,或作为交互式工具的一部分。
  7. create_drawing_object_xld

    • 功能:创建一个基于扩展线描述(XLD)的绘图对象。
    • 参数:通常包括XLD数据,这些数据描述了图像的轮廓或多边形。
    • 应用:用于标记图像中的复杂形状或轮廓,如边缘检测、轮廓提取等任务的结果。
  8. 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、示例演示

交互修改的区域

Hi~ 可私信我了解后再进行下载~ 本资源上传时,遗漏了两个文件,分别是:data_filter_keep_order_output_index.hdvp 以及 IntensityImageToPiontsCloudImage.hdvp,购买了该资源的同学,给我留言,我会私信发给你们。 1.基于halcon算法平台; 2.提供深度图源文件以及解压密码; 3.代码预览: */****************************** * @文档名称: 基于点云的平面度测量。 * @作者: hugo * @版本: 1.1 * @日期: 2021-6-20 * @描述: 该方法支持点云的平面的平面度测量。 ********************************/ dev_update_window ('on') dev_get_window (WindowHandle) read_image (imageReal, './replay_38893_2021-6-7.tif') xResolution:=0.06 yResolution:=0.06 zResolution:=0.001 ScaleFactor:=[xResolution,yResolution,zResolution] *采样区域1 create_drawing_object_rectangle2 (300, 120, rad(90), 30, 20, DrawID) set_drawing_object_params (DrawID, 'color', 'forest green') set_drawing_object_params (DrawID, 'line_width', 1) attach_drawing_object_to_window (WindowHandle, DrawID) .......... *平面度 height:=theta/zScale*0.001 *可视化高度差效果 visParamName := ['lut','alpha_0','intensity','color_1'] visParamValue := ['hsi',0.7,'coord_z','yellow'] Labels := ['','平面度:'+height+'mm',''] objs:=[ObjectModel3Ds[2],final_ObjectModel3Ds] visualize_object_model_3d (WindowHandle, objs, [], [], visParamName, visParamValue, 'Edited by AmazingRobot+', [Labels], '', PoseOut) *stop () clear_object_model_3d (plane_balls) for Index := 0 to |final_ObjectModel3Ds|-1 by 1 clear_object_model_3d (final_ObjectModel3Ds[Index]) endfor return () 谢谢您的信任~
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

F-Halcon

浏览即鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值