- dev_close_window()
- dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
- read_image (Image913523B340af66e82c64f, 'image/9_13523_b340af66e82c64f.png')
- rgb1_to_gray(Image913523B340af66e82c64f, GrayImage)
- dev_display(GrayImage)
- gen_rectangle2(Rectangle, 714.6, 883, 0, 69.36, 9.86)
- gen_circle(Circle, 715.1, 881.93, 31.75)
- difference(Rectangle, Circle, RegionDifference)
- gen_contour_region_xld (RegionDifference, Contours, 'border')
- ***建立shape model
- create_shape_model_xld(Contours, 'auto', -1.57, 3.14, 'auto', 'auto', 'ignore_local_polarity', 15, ModelID)
- get_shape_model_contours(ModelContours, ModelID, 1)
- find_shape_model(GrayImage, ModelID, -1.57, 3.14, 0.5, 3, 0.5, ['least_squares','max_deformation 2'], 0, 0.1, Row2, Column2, Angle, Score)
- dev_update_off()
- for i:=0 to |Row2|-1 by 1
- vector_angle_to_rigid (0, 0, 0, Row2, Column2, Angle, HomMat2D)
- affine_trans_contour_xld(ModelContours, ContoursAffineTrans, HomMat2D)
- gen_region_contour_xld (ContoursAffineTrans, Region, 'filled')
- union1(Region, RegionUnion)
- shape_trans(RegionUnion, RegionTrans, 'rectangle2')
- difference(RegionTrans, RegionUnion, RegionDifference1)
- opening_circle(RegionDifference1, RegionOpening, 2.5)
- dilation_rectangle1(RegionOpening, RegionDilation, 11, 25)
- smallest_rectangle2(RegionUnion, Row3, Column3, Phi1, Length11, Length21)
- gen_rectangle2(Rectangle1, Row3, Column3, Phi1+1.57, Length11-25, Length21)
- difference(Rectangle1, RegionDilation, RegionDifference2)
- erosion_circle(RegionDifference2, RegionErosion, 2.5)
- connection(RegionErosion, ConnectedRegions)
- count_obj(ConnectedRegions, Number)
- intensity(ConnectedRegions, GrayImage, Mean, Deviation)
- **用MLP 分類器會比較穩定
- ***把Mean,Deviation 或是其他region等變數作為MLP輸入, 訓練MLP 即可分類結果0,1 (Pass,Fail)
- **一個螺絲有兩的分類結果 任一個Fail 就是Fail
- if((Mean[0]>160 and Deviation[0]>45) or(Mean[1]>160 and Deviation[1]>45))
- dev_disp_text('Fail', 'image', Row2+100,Column2, 'magenta', [], [])
- else
- dev_disp_text('Pass', 'image', Row2+100,Column2, 'magenta', [], [])
- endif
- endfor
复制代码
|