檢測金屬圓環表面的凹痕

阿卡基YUAN發表於2019-03-18

dev_close_window () 
dev_update_window ('off') 
read_image (Image, 'I:/Halcon/photo/圓環凹痕檢測.jpg') 
rgb1_to_gray (Image, GrayImage) 
get_image_size (GrayImage, Width, Height) 
dev_open_window (0, 0, Width, Height, 'black', WindowHandle) 
dev_display (GrayImage) 
threshold (GrayImage, Region, 100, 255) 
connection (Region, ConnectedRegions) 
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 6000, 99999) 
closing_circle (SelectedRegions, RegionClosing, 1) 
erosion_circle (RegionClosing, RegionErosion, 2) 
reduce_domain (GrayImage, RegionErosion, ImageReduced) 
emphasize (ImageReduced, ImageEmphasize, 5, 5, 3) 
scale_image_max (ImageEmphasize, ImageScaleMax) 
threshold (ImageScaleMax, Dent, 0, 10) 
area_center (Dent, Area, Row, Column) 
gen_rectangle2 (Rectangle, Row, Column, 0, 5, 5) 
dev_clear_window () 
dev_display (Image) 
dev_display (Dent) 
dev_set_draw ('margin') 
dev_display (Rectangle) 
set_display_font (WindowHandle, 8, 'mono', 'true', 'false') 
disp_message (WindowHandle, Area+' dent', 'image', Row-15, Column-5, 'red', 'false')

 

read_image (Image1, 'C:/Users/Administrator/Desktop/新建資料夾 (3)/13_27434_9966b561465415c.jpg') 
rgb1_to_gray(Image1, GrayImage) 
invert_image (GrayImage, Image) 
get_image_size (Image, Width, Height) 


* Optimize the fft speed for the specific image size 
optimize_rft_speed (Width, Height, 'standard') 


Sigma1 := 5 
Sigma2 :=1 
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height) 
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height) 
sub_image (GaussFilter2, GaussFilter1, Filter, 1, 0) 


rft_generic (Image, ImageFFT, 'to_freq', 'sqrt', 'complex', Width) 
convol_fft (ImageFFT, Filter, ImageConvol) 
rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'sqrt', 'byte', Width) 


threshold (GrayImage, Regions, 134, 255) 
connection (Regions, ConnectedRegions) 
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5229.36, 20000) 
connection (SelectedRegions, ConnectedRegions) 
erosion_circle (ConnectedRegions, RegionErosion, 2.5) 
reduce_domain (ImageFiltered, RegionErosion, ImageReduced) 
min_max_gray (RegionErosion, ImageReduced, 0, Min, Max, Range) 
threshold (ImageReduced, RegionDynThresh, max([5.55,Max * 0.8]), Max ) 


dev_display (Image1) 
dev_display (RegionDynThresh)

 

相關文章