一维卡尺边缘对

一、代码部分

* 一维卡尺 边缘对

read_image (Image, 'printer_chip/printer_chip_01')

*打开助手操作生成代码

* Measure 02: Code generated by Measure 02
* Measure 02: Prepare measurement
AmplitudeThreshold := 40
RoiWidthLen2 := 5
set_system ('int_zooming', 'true')
* Measure 02: Coordinates for line Measure 02 [0]
LineRowStart_Measure_02_0 := 147.099
LineColumnStart_Measure_02_0 := 497.926
LineRowEnd_Measure_02_0 := 145.627
LineColumnEnd_Measure_02_0 := 915.834
* Measure 02: Convert coordinates to rectangle2 type
TmpCtrl_Row := 0.5*(LineRowStart_Measure_02_0+LineRowEnd_Measure_02_0)
TmpCtrl_Column := 0.5*(LineColumnStart_Measure_02_0+LineColumnEnd_Measure_02_0)
TmpCtrl_Dr := LineRowStart_Measure_02_0-LineRowEnd_Measure_02_0
TmpCtrl_Dc := LineColumnEnd_Measure_02_0-LineColumnStart_Measure_02_0
TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
TmpCtrl_Len2 := RoiWidthLen2

* Measure 02: Create measure for line Measure 02 [0]
* Measure 02: Attention: This assumes all images have the same size!
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1600, 1200, 'nearest_neighbor', MsrHandle_Measure_02_0)
* Measure 02: ***************************************************************
* Measure 02: * The code which follows is to be executed once / measurement *
* Measure 02: ***************************************************************
* Measure 02: The image is assumed to be made available in the
* Measure 02: variable last displayed in the graphics window
copy_obj (Image, Image, 1, 1)


*边缘对测量
*边缘对,两点成对,一对必有第一个点和第二个点,必须先理解这个概念。
* 输出结果 Row1 第一行 (边缘对第一个点row)
* 输出结果 Column1 第一列(边缘对第一个点column)
* 输出结果 Row2 第二行(边边缘对第第二个点row)
* 输出结果 Column2 第二列(边缘对第二个点column)
* 输出结果 Width 边缘对内部的距离
* 输出结果 Distance 边缘对之间的距离
measure_pairs (Image, MsrHandle_Measure_02_0, 1, AmplitudeThreshold, 'all', 'all', \
               Row1_Measure_02_0, Column1_Measure_02_0, Amplitude1_Measure_02_0, \
               Row2_Measure_02_0, Column2_Measure_02_0, Amplitude2_Measure_02_0, \
               Width_Measure_02_0, Distance_Measure_02_0)

*--生成代码结束

*显示第一个点
gen_cross_contour_xld (Cross, Row1_Measure_02_0[0], Column1_Measure_02_0[0], 36, 0.785398)

 

二、生成代码

1.打开助手,打开Measure窗口,绘制直线

 

2.勾选边缘对,生成代码

 

三、练习作业

计算第一排针脚的个数,标注第20针脚的位置

* 一维卡尺作业,计算针脚个数,标准第20个
read_image (Image, 'D:/hoclan/bianyuandui.png')

*打开助手,绘制Measure直线,插入代码
* Measure 03: Code generated by Measure 03
* Measure 03: Prepare measurement
AmplitudeThreshold := 40
RoiWidthLen2 := 5
set_system ('int_zooming', 'true')
* Measure 03: Coordinates for line Measure 03 [0]
LineRowStart_Measure_03_0 := 63.125
LineColumnStart_Measure_03_0 := 34.6127
LineRowEnd_Measure_03_0 := 63.125
LineColumnEnd_Measure_03_0 := 949.966
* Measure 03: Convert coordinates to rectangle2 type
TmpCtrl_Row := 0.5*(LineRowStart_Measure_03_0+LineRowEnd_Measure_03_0)
TmpCtrl_Column := 0.5*(LineColumnStart_Measure_03_0+LineColumnEnd_Measure_03_0)
TmpCtrl_Dr := LineRowStart_Measure_03_0-LineRowEnd_Measure_03_0
TmpCtrl_Dc := LineColumnEnd_Measure_03_0-LineColumnStart_Measure_03_0
TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
TmpCtrl_Len2 := RoiWidthLen2
* Measure 03: Create measure for line Measure 03 [0]
* Measure 03: Attention: This assumes all images have the same size!
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 988, 1018, 'nearest_neighbor', MsrHandle_Measure_03_0)
* Measure 03: ***************************************************************
* Measure 03: * The code which follows is to be executed once / measurement *
* Measure 03: ***************************************************************
* Measure 03: The image is assumed to be made available in the
* Measure 03: variable last displayed in the graphics window
copy_obj (Image, Image, 1, 1)
* Measure 03: Execute measurements
measure_pairs (Image, MsrHandle_Measure_03_0, 1, AmplitudeThreshold, 'all', 'all', Row1_Measure_03_0, Column1_Measure_03_0, Amplitude1_Measure_03_0, Row2_Measure_03_0, Column2_Measure_03_0, Amplitude2_Measure_03_0, Width_Measure_03_0, Distance_Measure_03_0)
* Measure 03: Do something with the results
*--插入代码结束

*计算第20个针脚的位置,并生成矩形2轮廓
gen_rectangle2_contour_xld (Rectangle, Row1_Measure_03_0[19]+Row2_Measure_03_0[19]-Row1_Measure_03_0[19], Column1_Measure_03_0[19]+Column2_Measure_03_0[19]-Column1_Measure_03_0[19], rad(90), 25, \
                            Column2_Measure_03_0[20]-Column1_Measure_03_0[20])

*显示信息
dev_disp_text ('这是第20个针脚,共有'+|Row1_Measure_03_0|+'个针脚', 'image', Row1_Measure_03_0[19]+Row2_Measure_03_0[19]-Row1_Measure_03_0[19], Column1_Measure_03_0[19]+Column2_Measure_03_0[19]-Column1_Measure_03_0[19], 'blue', [], [])

 

posted @ 2024-09-02 10:52  别动我的猫  阅读(11)  评论(0编辑  收藏  举报