抓边调试代码

* Matching 02: BEGIN of generated code for model initialization
set_system ('border_shape_models', 'false')
* Matching 02: Obtain the model image
read_image (Image, 'E:/下载/4倍镜400G-SM/20210417-135739.bmp')
* Matching 02: build the ROI from basic regions
Rect1Row:=613.231
Rect1Col:= 1174.56
RectLength1:=286.408
RectLength2:=134.588
*draw_line (3601, Row11, Column1, Row2, Column2)
Row11:=310.541
Column1:=1019.722
Row2:=310.541
Column2:=1364
LinePara:=[Row11, Column1, Row2, Column2]
gen_region_line (Lines1,Row11, Column1, Row2, Column2)
gen_cross_contour_xld (Cross, Rect1Row, Rect1Col, 60, 0.785398)
gen_rectangle2 (ModelRegion, 613.231, 1174.56, rad(-90), 286.408, 134.588)

line_position (Row11, Column1, Row2, Column2, RowCenter, ColCenter, Length, Phi1)

*计算点和线之间的距离
*distance_pl (Rect1Row, Rect1Col, Row11, Column1, Row2, Column2, Distance1)
Row1M:=-RowCenter
Row2M:=-RowCenter
Column1M:=-Length/2
Column2M:=Length/2
gen_region_line (RegionLines,Rect1Row+Row1M,Rect1Col+Column1M, Rect1Row+Row2M,  Rect1Col+Column2M)

LineParaM:=[Row1M,Column1M, Row2M,  Column2M]
* Matching 02: reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
* Matching 02: create the shape model
*create_shape_model (TemplateImage, 7,0, 360, 'auto', ['point_reduction_high','no_pregeneration'], 'use_polarity', [33,49,7], 3, ModelId)
read_shape_model ('E:/demo/MachineVisionSoftWare/MachineVisionSoftWare/bin/x86/Debug/shmFiles/CreateShapeModel20230310141416.shm', ModelId)
* Matching 02: get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelId, 1)
* Matching 02: END of generated code for model initialization
* Matching 02: BEGIN of generated code for model application
* Matching 02: the following operations are usually moved into
* Matching 02: that loop where the aquired images are processed
* Matching 02: Find the model
read_image (Image1, 'E:/下载/4倍镜400G-SM/20210417-135739.bmp')
find_shape_model (Image1, ModelId, 0, 360, 0.5, 0, 0.5, 'least_squares', [7,1], 0.75, ModelRow, ModelColumn, ModelAngle, ModelScore)
* Matching 02: transform the model contours into the detected positions
for MatchingObjIdx := 0 to |ModelScore| - 1 by 1
    hom_mat2d_identity (HomMat)
    hom_mat2d_translate (HomMat, ModelRow[MatchingObjIdx], ModelColumn[MatchingObjIdx], HomMat2DTranslate)
    hom_mat2d_rotate (HomMat2DTranslate, ModelAngle[MatchingObjIdx],  ModelRow[MatchingObjIdx], ModelColumn[MatchingObjIdx], HomMat2DRotate)
    *get_shape_model_contours (ModelContours1, ModelId, 1)    
    affine_trans_contour_xld (ModelContours, TransContours, HomMat2DRotate)
    dev_display (TransContours)
    *affine_trans_region (ModelRegion, RegionAffineTrans, HomMat2DTranslate, 'nearest_neighbor')
    gen_region_contour_xld (TransContours, Region, 'margin')
    *smallest_rectangle2 (Region, Row, Column, Phi, Length1, Length2)
endfor
*orientation_region (RegionAffineTrans, Phi1)
affine_trans_pixel (HomMat2DRotate,Row1M,Column1M, Rect1RowCheck, Rect1ColCheck)
affine_trans_pixel (HomMat2DRotate, Row2M,  Column2M, Rect2RowCheck, Rect2ColCheck)
gen_region_line (Line1,Rect2RowCheck, Rect2ColCheck,Rect1RowCheck, Rect1ColCheck)

dev_display (TransContours)
dev_display (Region)
MeasureThreshold:=100
LineParaCheck:=[Rect1RowCheck, Rect1ColCheck,Rect2RowCheck, Rect2ColCheck]
*创建卡尺句柄
create_metrology_model (MetrologyHandle)
*设置被测图尺寸
set_metrology_model_image_size (MetrologyHandle, 120, 40)
*添加直线模型,卡尺尺寸设定,边缘强度设定
add_metrology_object_line_measure (MetrologyHandle, Rect1RowCheck, Rect1ColCheck,Rect2RowCheck, Rect2ColCheck, 20, 5, 1, 30, [], [], Index1)
*add_metrology_object_generic (MetrologyHandle, 'line', LineParaCheck, 20, 3, 1, 40, [], [], Index)
set_metrology_object_param (MetrologyHandle, 'all', 'num_measures',15)

*执行测量
apply_metrology_model (Image1, MetrologyHandle)
*获取测量Contours
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row3, Column3)

*dev_display (Contours)
*获取测量数据
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
*获取测量直线
get_metrology_object_result_contour (Contour, MetrologyHandle,'all', 'all', 1.5)
* Matching 02: Clear model when done
clear_shape_model (ModelId)
* Matching 02: END of generated code for model application

你可能感兴趣的:(工作记录,计算机视觉)