|  | 
 
| 光度立体视觉缺陷检测: halcon12 + win32
 例如:四个角度,各拍摄一张图,供4张图,然后进行光度立体视觉缺陷检测,
 
 
 复制代码read_image (Images, 'photometric_stereo/blister_back_0' + [1:4])
for I := 1 to 4 by 1
    Message := 'Acquire image ' + I + ' of 4'
    select_obj (Images, ObjectSelected, I)
    dev_display (ObjectSelected)
    disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    wait_seconds (0.5)
endfor
* 
* Apply photometric stereo to determine the albedo and the surface gradient.
Tilts := [6.1,95.0,-176.1,-86.8]   
Slants := [41.4,42.6,41.7,40.9]
ResultType := ['gradient','albedo']
photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, ResultType, 'poisson', [], [])
* 
* Display the albedo image
dev_display (Albedo)
stop ()
* 
* Calculate the gaussian curvature of the surface
* using the gradient field as input for the operator
* derivate_vector_field.
* Defects are usually easy to detect in the curvature image.
derivate_vector_field (Gradient, GaussCurvature, 1, 'gauss_curvature')
* 
* Detect defects
* 
* Segment the tablet areas in the curvature image
regiongrowing (GaussCurvature, Regions, 1, 1, 0.001, 250)
select_shape (Regions, TabletRegions, ['width','height'], 'and', [150,150], [200,200])
shape_trans (TabletRegions, TabletRegions, 'convex')
union1 (TabletRegions, TabletRegions)
erosion_circle (TabletRegions, TabletRegions, 3.5)
* Search for defects inside the tablet areas
reduce_domain (GaussCurvature, TabletRegions, ImageReduced)
abs_image (ImageReduced, ImageAbs)
threshold (ImageAbs, Region, 0.03, 255)
closing_circle (Region, RegionClosing, 10.5)
connection (RegionClosing, ConnectedRegions)
select_shape (ConnectedRegions, Defects, 'area', 'and', 10, 99999)
area_center (Defects, Area, Row, Column)
gen_circle (Circle, Row, Column, gen_tuple_const(|Row|,20.5))
* Display the defects in curvature image
dev_set_draw ('margin')
dev_display (Albedo)
dev_display (Circle)
disp_message (WindowHandle, 'Defect in albedo image', 'window', 12, 12, 'black', 'true')
参考:
 【1】检测效果:https://tieba.baidu.com/p/1712630404?red_tag=2883704820
 【2】论文:https://wenku.baidu.com/view/564 ... 25.html?from=search
 
 
 
 
 
 
 | 
 
x本帖子中包含更多资源您需要 登录 才可以下载或查看,没有帐号?立即注册  |