前面对Halcon光度立体法文档进行了解析https://blog.csdn.net/qq_18620653/article/details/109074938,如果还有疑问,下面结合例程又做了进一步说明,希望对你有所帮助。
模拟成像场景
根据例程代码,为了便于理解,我将成像场景大致模拟如下(倾心讲解):
Tilts 解释如下:
* 这个例子展示的是利用光度立体法检测洗发水瓶的标签缺陷
* 程序初始化
dev_close_window ()
dev_update_off ()
dev_open_window (0, 0, 640, 512, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
Message := 'Inspect the label of a shampoo bottle'
Message[1] := 'using photometric stereo. In this case four'
Message[2] := 'different light orientations were used.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* 在窗口分别显示四个不同光照方向所成的像
read_image (Images, 'photometric_stereo/shampoo_label_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
* 应用光度立体法获取梯度以及反射率图
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', [], [])
*
* 显示反射率图
dev_display (Albedo)
disp_message (WindowHandle, 'Albedo image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* 对梯度图像进行高斯导数卷积操作(后续会对算子derivate_vector_field深度剖析)
derivate_vector_field (Gradient, MeanCurvature, 1.0, 'mean_curvature')
*
* 缺陷检测
*
* 对卷积后的图像Blob分析
threshold (MeanCurvature, Region, -10, -0.07)
opening_circle (Region, RegionOpening, 1)
connection (RegionOpening, ConnectedRegions)
select_shape (ConnectedRegions, Defects, 'area', 'and', 50, 99999)
shape_trans (Defects, Circle, 'outer_circle')
* 在图像上显示缺陷区域
dev_set_draw ('margin')
dev_set_color ('red')
dev_set_line_width (2)
dev_display (MeanCurvature)
dev_display (Circle)
Message := 'The defect can easily be detected'
Message[1] := 'in the surface curvature image'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
stop ()
*
dev_set_draw ('margin')
dev_set_color ('red')
dev_display (Albedo)
dev_display (Circle)
disp_message (WindowHandle, 'Defect in albedo image', 'window', 12, 12, 'black', 'true')