上述代码是使用HALCON软件编写的脚本,用于处理图像并提取盲文字符。HALCON是一款用于机器视觉和图像分析的高级软件,广泛应用于工业自动化、医学图像处理等领域。这段代码主要解决的问题是利用光度立体技术(Photometric Stereo)来重建盲文字符的高度场,并对其进行分割和识别
dev_close_window ()
dev_update_off ()
read_image (Image, ‘photometric_stereo/embossed_01’)
get_image_size (Image, WindowWidth, WindowHeight)
dev_open_window_fit_size (0, 0, WindowWidth, WindowHeight, WindowWidth * 0.6, WindowHeight * 0.6, WindowHandle)
set_display_font (WindowHandle, 14, ‘mono’, ‘true’, ‘false’)
dev_display (Image)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
disp_message (WindowHandle, ‘Extract braille characters using\nphotometric stereo. For this approach\nsix different light setups were used.’, ‘window’, 10, 10, ‘black’, ‘true’)
stop ()
*
- Show input images (illuminated differently)
FileNames := []
for I := 1 to 6 by 1
FileNames := [FileNames,‘photometric_stereo/embossed_’ + I$‘.2’]
endfor
read_image (Images, FileNames)
count_obj (Images, NumImages)
for I := 1 to NumImages by 1
select_obj (Images, ObjectSelected, I)
dev_display (ObjectSelected)
wait_seconds (0.5)
endfor - Apply photometric stereo to determine the height field
photometric_stereo (Images, Height, Gradient, Albedo, [70,50,70,50,70,50], [0,0,90,90,180,180], ‘all’, ‘rft_cyclic’, [], [])
mean_image (Height, ImageMean, 61, 61)
sub_image (Height, ImageMean, ImageSub, 1, 0)
dev_display (ImageSub)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
disp_message (WindowHandle, ‘Reconstruct the height field\napplying photometric stereo’, ‘window’, 10, 10, ‘black’, ‘true’)
stop ()
dev_display (Image) - Shade a height field
disp_message (WindowHandle, ‘Shade the height field\nof the braille dots’, ‘window’, 10, 10, ‘black’, ‘true’)
wait_seconds (2)
for I := 0 to 360 by 10
shade_height_field (ImageSub, ShadedFace, 45, I, 1, 0, ‘false’)
dev_display (ShadedFace)
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop () - Segment brailles dots
threshold (ImageSub, Region, 0.35, 1000)
dev_set_draw (‘margin’)
dev_set_line_width (4)
dev_set_color (‘green’)
dev_display (Image)
dev_display (Region)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
disp_message (WindowHandle, ‘Segment single dots’, ‘window’, 10, 10, ‘black’, ‘true’)
stop () - Group brailles dots to characters
closing_rectangle1 (Region, RegionClosing, 200, 60)
connection (RegionClosing, ConnectedRegions)
count_obj (ConnectedRegions, Number)
dev_display (Image)
dev_set_colored (12)
for I := 1 to Number by 1
select_obj (ConnectedRegions, ObjectSelected, I)
intersection (ObjectSelected, Region, RegionIntersection)
partition_dynamic (RegionIntersection, Partitioned, 135, 20)
dev_display (Partitioned)
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
disp_message (WindowHandle, ‘Finally, group the dots that describe\nindividual braille characters’, ‘window’, 10, 10, ‘black’, ‘true’)
stop () - Another way is to use the mean curvature to extract the dots. Note that the Gradient must be calulated only.
- This version is faster because no height field must be calculated.
photometric_stereo (Images, Height1, Gradient1, Albedo1, [70,50,70,50,70,50], [0,0,90,90,180,180], ‘gradient’, ‘rft_cyclic’, [], [])
derivate_vector_field (Gradient1, Result, 1, ‘mean_curvature’)
dev_display (Result)
disp_message (WindowHandle, ‘Alternative Solution: Use gauss curvature of gradient image\nto segment the dots’, ‘window’, 10, 10, ‘black’, ‘true’)
stop ()
threshold (Result, Region, -10, 0)
connection (Region, ConnectedRegions1)
fill_up (ConnectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions1, [‘area’,‘circularity’], ‘and’, [150,0.8], [99999,1])
count_obj (SelectedRegions1, Number)
union1 (SelectedRegions1, RegionUnion)
closing_rectangle1 (RegionUnion, RegionClosing1, 200, 60)
connection (RegionClosing1, ConnectedRegions)
count_obj (ConnectedRegions, Number)
dev_display (Image)
dev_set_colored (12)
for I := 1 to Number by 1
select_obj (ConnectedRegions, ObjectSelected, I)
intersection (ObjectSelected, RegionUnion, RegionIntersection)
partition_dynamic (RegionIntersection, Partitioned, 135, 20)
dev_display (Partitioned)
endfor
disp_continue_message (WindowHandle, ‘black’, ‘true’)
disp_message (WindowHandle, ‘Finally, group the dots that describe\nindividual braille characters’, ‘window’, 10, 10, ‘black’, ‘true’)
以下是代码的详细解释:
dev_close_window() 和 dev_update_off():关闭当前显示窗口并关闭自动更新显示。
read_image(Image, ‘photometric_stereo/embossed_1’):读取名为 ‘embossed_1’ 的图像文件。
get_image_size(Image, WindowWidth, WindowHeight):获取图像的宽度和高度。
dev_open_window_fit_size(…):根据图像大小打开一个新的显示窗口。
set_display_font(…):设置显示窗口的字体样式。
dev_display(Image):在新窗口中显示图像。
disp_continue_message(…) 和 disp_message(…):在窗口中显示继续消息和文本消息。
stop():暂停执行,等待用户操作。
接下来的循环读取六张不同光照条件下的图像,并逐个显示它们。
photometric_stereo(…):应用光度立体技术来确定高度场、梯度和反照率。
mean_image(…) 和 sub_image(…):计算高度场的平均图像,并从原始高度场中减去平均图像。
shade_height_field(…):对高度场进行阴影处理,以更清晰地显示盲文点的三维形状。
threshold(…) 和 connection(…):对图像进行阈值处理,并将连续的区域连接起来。
closing_rectangle1(…) 和 select_shape(…):使用闭运算和形状选择来进一步处理和筛选区域。
union1(…) 和 partition_dynamic(…):将区域合并并动态分割。
photometric_stereo(…) 和 derivate_vector_field(…):另一种解决方案,使用梯度图像的高斯曲率来分割点。
threshold(…)、connection(…) 和 fill_up(…):对高斯曲率图像进行阈值处理,连接区域,并填充空洞。
select_obj(…) 和 dev_display(…):选择对象并显示结果。
这段代码通过光度立体技术重建盲文字符的高度场,然后通过图像处理技术(如阈值分割、区域连接、形态学操作等)来分割和识别盲文字符。最后,提供了一种替代方案,使用梯度图像的高斯曲率来直接分割点,这种方法更快,因为不需要计算整个高度场。