https://www.icode9.com/content-4-689857.html
MeasureLines [] null
read_image (Image, 'G:/Workspace/2020/Images/chip/dip_switch_training_01.png')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
dev_set_draw ('margin')
dev_set_color ('blue')
******** Make Mwsure Window
*left line
draw_line(WindowHandle, Row1, Column1, Row2, Column2)
gen_region_line (RegionLines, Row1, Column1, Row2, Column2)
dev_display (RegionLines)
*right line
draw_line (WindowHandle, Row11, Column11, Row21, Column21)
gen_region_line (RegionLines1, Row11, Column11, Row21, Column21)
dev_display (RegionLines1)
stop()
**************** Make shape model
*rect
draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
reduce_domain (Image, Rectangle, ImageReduced)
create_shape_model (ImageReduced, 'auto', 0, rad(360), 'auto', 'no_pregeneration', 'use_polarity', 'auto', 'auto', ModelID)
find_shape_model (ImageReduced, ModelID, 0, rad(360), 0.5, 1, 0, 'least_squares', 0, 0.7, Row3, Column3, Angle, Score)
get_shape_model_contours (ModelContours, ModelID, 1)
stop()
*************** Make Measure Model
create_metrology_model (MetrologyHandle)
set_metrology_model_image_size (MetrologyHandle, Width, Height)
*添加测量直线对象到测量模型中
line1 := [Row1, Column1, Row2, Column2]
line2 := [ Row11, Column11, Row21, Column21]
*add_metrology_object_generic (MetrologyHandle, 'circle', line2, 20, 5, 1, 30, [], [], Index)
*add_metrology_object_generic (MetrologyHandle, 'line', [line1, line2], 20, 5, 1, 30, [], [], Index)
add_metrology_object_generic (MetrologyHandle, 'line', [line1, line2], 20, 5, 1, 30, [], [], MetrologyLine)
*获取测量模型里的模型轮廓
*get_metrology_object_model_contour (Contour, MetrologyHandle, 0, 1.5)
get_metrology_object_model_contour (Contour, MetrologyHandle, 'all', 1.5)
*获取测量模型里的测量区域
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row4, Column4)
dev_display (Image)
dev_display (Contours)
*设置测量对象的参考坐标系原点在模板坐标位置
*set_metrology_model_param (MetrologyHandle, 'camera_param', [])
set_metrology_model_param (MetrologyHandle, 'reference_system', [Row3, Column3, Angle])
stop()
**************** Begin testing
ImageFiles := []
ImageFiles[0] := 'G:/Workspace/2020/Images/chip/dip_switch_training_01.png'
ImageFiles[1] := 'G:/Workspace/2020/Images/chip/dip_switch_training_02.png'
ImageFiles[2] := 'G:/Workspace/2020/Images/chip/dip_switch_training_03.png'
ImageFiles[3] := 'G:/Workspace/2020/Images/chip/dip_switch_training_04.png'
ImageFiles[4] := 'G:/Workspace/2020/Images/chip/dip_switch_training_05.png'
ImageFiles[5] := 'G:/Workspace/2020/Images/chip/dip_switch_training_06.png'
ImageFiles[6] := 'G:/Workspace/2020/Images/chip/dip_switch_training_07.png'
for Index := 1 to |ImageFiles|-1 by 1
dev_clear_window ()
*设置区域填充模式
dev_set_draw ('fill')
read_image (Image1, ImageFiles[Index])
dev_display (Image1)
find_shape_model (Image1, ModelID, 0, rad(360), 0.4, 1, 0, 'least_squares', 0, 0.6, Row5, Column5, Angle1, Score1)
*对齐测量模型
*align_metrology_model (MetrologyHandle, 0, 0, Angle1)
align_metrology_model (MetrologyHandle, Row5, Column5, Angle1)
*测量并对测量区域拟合几何形状
apply_metrology_model (Image1, MetrologyHandle)
*获取测量结果里的开始行坐标
*get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'row_begin', RowBegin)
*get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'column_begin', ColBegin)
*get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'row_end', RowEnd)
*get_metrology_object_result (MetrologyHandle, 0, 'all', 'result_type', 'column_end', ColEnd)
get_metrology_object_result (MetrologyHandle, MetrologyLine, 'all', 'result_type', 'row_begin', RowBegin)
get_metrology_object_result (MetrologyHandle, MetrologyLine, 'all', 'result_type', 'column_begin', ColBegin)
get_metrology_object_result (MetrologyHandle, MetrologyLine, 'all', 'result_type', 'row_end', RowEnd)
get_metrology_object_result (MetrologyHandle, MetrologyLine, 'all', 'result_type', 'column_end', ColEnd)
*获取测量区域
get_metrology_object_measures (SearchContour, MetrologyHandle, 'all', 'all', Row6, Column6)
*get_metrology_object_result_contour (Contour1, MetrologyHandle, 0, 'all', 1.5)
get_metrology_object_result_contour (MeasureLines, MetrologyHandle, 'all', 'all', 1.5)
dev_display (Image1)
dev_set_color ('green')
dev_display (SearchContour)
dev_set_color ('red')
dev_display (MeasureLines)
endfor