摘要
功能
手动拖拽测量矩形进行测量
基本步骤如下
1.加载图像
2.创建测量矩形
3.人机交互
Halcon代码:
*1 图像加载
dev_close_window ()
read_image (Image, '工件2.bmp')
get_image_size (Image, Width, Height)
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')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*2 创建测量矩形
create_drawing_object_rectangle2 (300, 530, rad(90), 90, 20, DrawID)
set_drawing_object_params (DrawID, 'color', 'red')
* Attach the drawing object and the image to the window
attach_drawing_object_to_window (WindowHandle, DrawID)
attach_background_to_window (Image, WindowHandle)
get_font (WindowHandle, Font)
*3 交互
Button := 0
while (Button != 4)
try
perform_measurement (Image, DrawID, Width, Height, RowEdge, ColumnEdge)
display_results (RowEdge, ColumnEdge, WindowHandle)
* Check the mouse position and button
get_mposition (WindowHandle, Row, Column, Button)
catch (Exception)
* Keep waiting until mouse button is
* positioned in the window
endtry
endwhile
*
* Detach the drawing objects
dev_clear_window ()
detach_drawing_object_from_window (WindowHandle, DrawID)
detach_background_from_window (WindowHandle)
* Clear the drawing objects
clear_drawing_object (DrawID)
* dev_set_preferences ('suppress_handled_exceptions_dlg', SuppressExceptDlg)
dev_clear_window ()
dev_display (Image)
disp_message (WindowHandle, 'The drawing object has been cleared', 'window', 10, 10, 'red', 'false')
更多详情了解:https://blog.youkuaiyun.com/qq_32015315/article/details/141663063