当前位置: 首页 > 工具软件 > Braille-Font > 使用案例 >

phot_stereo_braille

长孙德惠
2023-12-01

* Example program to demonstrate photometric stereo
* Input are 6 images taken from braille with light coming
* from different orientations and angles. After the height
* extraction, the dots are extracted and grouped to characters
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')

 类似资料:

相关阅读

相关文章

相关问答