Halcon Solution Guide I basics(5): 1D Measuring

Article column

My Halcon development CSDN column

Halcon learning practice project gitee repository

Recommended articles by CSDN Major blogger Halcon

Essay classification - Halcon introductory learning tutorial

Preface

Today we will learn about straight line distance measurement, which is mainly used to measure the distance between line segments between connected points. The feeling is used to get the accuracy of industrial products.

Article interpretation

  • One-dimensional ranging is very simple
  • An example of strong light and dark contrast is provided here
  • You can range the left and right spacing of the sample edges
  • The advantages of one-dimensional ranging are low overhead, fast speed and good effect.
    Insert image description here
    Insert image description here

flow chart

Get pictures->Create ranging objects->Ranging
Insert image description here

official case

Inspecting a Fuse

Insert image description here

  • Analyze the components of a line segment

Insert image description here

  • Makes a symmetry analysis measurement, returning the width and spacing of the edges of a symmetrical image
  • The program analyzes the latest part and obtains the XLD outline
    Insert image description here

There are a lot of operator concepts in this chapter

Halcon operator_measure_pairs

Introduction to the measure_pos operator of Halcon measurement (4)

Introduction to the gen_measure_rectangle2 operator of Halcon measurement (3)

Common image upsampling algorithms

measure_pos and measure_pairs operators in one-dimensional measurement

The two very important operators encountered here, [gen_measure_rectangle2] and [measure_pairs], are too abstract and require in-depth understanding. Select the operator and press F1 to enter the document. It's a bit painful for someone like me who is illiterate in English.

gen_measure_rectangle2

  • gen_measure_rectangle2 is used to process straight edges, perpendicular to the rectangle axis. The default direction of the rectangular axis is horizontal, that is, vertical edges are processed by default. If you want to process horizontal edges, you need to rotate the ROI area. Others are too spicy to watch.
    Insert image description here

mearsur_paris

This person is even more heavyweight, and the parameters of the operator are basically incomprehensible. Simply put, this is used to deal with symmetrical edges.

If Transition = ‘positive’, edge points with a transition from dark to light in the direction of the long axis of the rectangle will be returned in RowEdgeFirst and ColumnEdgeFirst. In this case, the corresponding edges with light and dark transitions are returned in RowEdgeSecond and ColumnEdgeSecond. If Transition = 'negative', the behavior is exactly the opposite. If Transition = ‘all’, the first detected edge defines the transition between RowEdgeFirst and ColumnEdgeFirst. That is, edge pairs with light-dark-light transitions or edge pairs with dark-light-dark transitions are returned depending on the position of the measurement object. This is suitable for measuring objects with different brightness relative to the background.
It’s better to show pictures to understand
Insert image description here

Insert image description here

Code comments

The first time I came across it, I really didn’t understand it. When I have the opportunity, I’ll look at other cases and integrate them.

* fuse.hdev: measuring the width of a fuse wire
* 
dev_update_window ('off')
dev_close_window ()
* ****
* step: acquire image
* ****
read_image (Fuse, 'fuse')
get_image_size (Fuse, Width, Height)
dev_open_window_fit_image (Fuse, 0, 0, Width, Height, WindowID)
set_display_font (WindowID, 12, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Fuse)
set_display_font (WindowID, 12, 'mono', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: 创建测距ROI
* ****
* -> 手动定义 ROI
Row := 297
Column := 545
Length1 := 80
Length2 := 10
* rad为度数转弧度。90表达逆时针旋转90°
Angle := rad(90)
* 生成2型矩阵。1型矩形:绝对坐标生成。2型矩形:中心点坐标+长宽+偏转角
gen_rectangle2 (ROI, Row, Column, Angle, Length1, Length2)
* -> 2型矩形测距,获得测距句柄,测试'bicubic'只是算法选择,对结果影响不大
gen_measure_rectangle2 (Row, Column, Angle, Length1, Length2, Width, Height, 'bicubic', MeasureHandle)
dev_display (ROI)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: measure
* ****
* 对称性测距。获得对称两边的数据
measure_pairs (Fuse, MeasureHandle, 1, 1, 'negative', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: visualize results
* ****
for i := 0 to |RowEdgeFirst| - 1 by 1
    * 设置边缘的上下边距
    gen_contour_polygon_xld (EdgeFirst, [-sin(Angle + rad(90)) * Length2 + RowEdgeFirst[i],-sin(Angle - rad(90)) * Length2 + RowEdgeFirst[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeFirst[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeFirst[i]])
    gen_contour_polygon_xld (EdgeSecond, [-sin(Angle + rad(90)) * Length2 + RowEdgeSecond[i],-sin(Angle - rad(90)) * Length2 + RowEdgeSecond[i]], [cos(Angle + rad(90)) * Length2 + ColumnEdgeSecond[i],cos(Angle - rad(90)) * Length2 + ColumnEdgeSecond[i]])
    * 绘画出上下边缘
    dev_set_color ('cyan')
    dev_display (EdgeFirst)
    dev_set_color ('magenta')
    dev_display (EdgeSecond)
    dev_set_color ('blue')
    * 设置text光标起点,和write_string搭配使用
    if (i == 0)
        set_tposition (WindowID, RowEdgeFirst[i] + 5, ColumnEdgeFirst[i] + 20)
    else
        set_tposition (WindowID, RowEdgeFirst[i] - 40, ColumnEdgeFirst[i] + 20)
    endif
    write_string (WindowID, 'width: ' + IntraDistance[i] + ' pix')
endfor
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: destroy measure object
* ****
close_measure (MeasureHandle)
dev_update_window ('on')
dev_clear_window ()

Inspect Cast Part

  • The goal this time is to measure the distance between the two holes
  • Use the ROI in radians to simplify the ranging operation
    Insert image description here
    Use an operator to obtain the corresponding ranging data
    Insert image description here

【1】1D Measuring——gen_measure_arc() operator

Insert image description here

*  Example for the application of the measure package
* including a lot of visualization operators
* 
read_image (Zeiss1, 'zeiss1')
get_image_size (Zeiss1, Width, Height)
dev_close_window ()
dev_set_draw ('margin')
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Zeiss1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 设置中心点坐标+半径+弧度起点+终点
Row := 275
Column := 335
Radius := 107

* disp_circle (WindowHandle, Row, Column, Radius)
AngleStart := -rad(55)
AngleExtent := rad(170)
dev_set_draw ('fill')
dev_set_color ('green')
dev_set_line_width (1)
* 得到弧度的起点
get_points_ellipse (AngleStart + AngleExtent, Row, Column, 0, Radius, Radius, RowPoint, ColPoint)
* 绘制弧度:中心坐标+弧度长度+弧度起点
disp_arc (WindowHandle, Row, Column, AngleExtent, RowPoint, ColPoint)
dev_set_line_width (3)
* 得到测距的ROI句柄
gen_measure_arc (Row, Column, Radius, AngleStart, AngleExtent, 10, Width, Height, 'bicubic', MeasureHandle)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 得到运行时间,没啥用
count_seconds (Seconds1)
* 看不懂为什么要重复10次,可能是为了计算运算花的时间吧
* n := 10
* for i := 1 to n by 1
*     measure_pos (Zeiss1, MeasureHandle, 1, 10, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
* endfor
* 得到边缘计算的结果
measure_pos (Zeiss1, MeasureHandle, 1, 10, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
count_seconds (Seconds2)
* disp_circle (WindowHandle, RowEdge, ColumnEdge, 5)
dev_set_color ('orange')
* 绘制交点
for i := 0 to |ColumnEdge|-1 by 1
    disp_circle (WindowHandle, RowEdge[i], ColumnEdge[i], 5)
endfor
* Time := (Seconds2 - Seconds1) / n
disp_continue_message (WindowHandle, 'black', 'true')
* stop ()
* 得到两点的距离
distance_pp (RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2], IntermedDist)
* dev_display (Zeiss1)
dev_set_color ('red')
* disp_circle (WindowHandle, RowEdge, ColumnEdge, RowEdge - RowEdge + 1)
* 绘制两点线段
disp_line (WindowHandle, RowEdge[1], ColumnEdge[1], RowEdge[2], ColumnEdge[2])
dev_set_color ('yellow')
disp_message (WindowHandle, 'Distance: ' + IntermedDist, 'image', 250, 80, 'yellow', 'false')
* dump_window (WindowHandle, 'tiff_rgb', 'C:\\Temp\\zeiss_result')
dev_set_line_width (1)
* disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()

Inspecting an IC Using Fuzzy Measuring

Insert image description here

Operator explanation

create_funct_1d_pairs (open the [x, y] pair)

Effect: Convert [x1,y1],[x2,y2]…[xn,yn]
into (1,x1,y1,x2,y2)

actual effect:

create_funct_1d_pairs ([0.0,0.3], [1.0,0.0], FuzzyAbsSizeDiffFunction)

Insert image description here

Insert image description here

Guess you like

Origin blog.csdn.net/qq_44695769/article/details/134632191