一維卡尺邊緣對

别动我的猫發表於2024-09-02

一、程式碼部分

* 一維卡尺 邊緣對

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', [], [])

相關文章