【halcon】带纹理的划痕检测 经测试鲁棒性好 可以检测任何方向的划痕!


read_image (Image928957880c86d59583515, 'E:/work/OpenCV/flaw.bmp')
***************** 角度设置****************
rotate_image (Image928957880c86d59583515, Image928957880c86d59583515, 0, 'constant')
get_image_size (Image928957880c86d59583515, Width, Height)
optimize_fft_speed (Width, Height, 'standard')
invert_image (Image928957880c86d59583515, ImageInvert)
fft_generic (ImageInvert, Imagefft, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
dev_display (Image928957880c86d59583515)
count_seconds (Seconds)


for I:= 0 to 17 by 1    
    par_start<vThreadID.at(I)> : tex_scra(Imagefft,region.at(I), Width, Height, I*10, len_xld.at(I))
endfor

count_seconds (Seconds1)
convert_vector_to_tuple (vThreadID, ThreadID)
par_join (ThreadID)
a:=(Seconds1-Seconds)*1000

disp_message (200000,'running time:' + a + 'ms', 'image', 12, 12, 'black', 'true')
count:=1
gen_empty_obj (EmptyObject)
for Index := 0 to 17  by 1
    re:= region.at(Index)
    len:= len_xld.at(Index)
    count_obj (re, Number)
    if( Number!=0)
      concat_obj (re, EmptyObject, EmptyObject)   
      disp_message (200000,'length:' + len , 'image', count*40, 12, 'black', 'true')
      count:=count+1
    endif
endfor


gen_gauss_filter (ImageGauss, 20, 1, rad(angle), 'none', 'dc_center', Width, Height)
convol_fft (Imagefft, ImageGauss, ImageConvol)
fft_generic (ImageConvol, ImageFFT1, 'from_freq', 1, 'sqrt', 'dc_center', 'byte')

get_domain (ImageFFT1, Domain)
erosion_rectangle1 (Domain, RegionErosion, 10, 10)
reduce_domain (ImageFFT1, RegionErosion, ImageReduced)

lines_gauss (ImageReduced, Lines, 0.6, 1, 3, 'light', 'true', 'gaussian', 'true')
union_collinear_contours_xld (Lines, UnionContours, 30, 1, 20, 0.1, 'attr_keep')
select_shape_xld (UnionContours, xld, 'contlength', 'and', 100, 1000)
length_xld (xld, len_xld)

return ()

猜你喜欢

转载自blog.csdn.net/qingzhuyuxian/article/details/92801033