测试效果
不同高度上拍摄几十张图像
三维重建出的样子
重建的代表深度的图
全景深图
废话
对焦测距是一种采用不同光学参数进行拍摄,在一系列物体图像中找出最清晰的像,并根据几何光学成像原理来计算物体深度的方法。其基本原理是,当镜头对焦于某一物体时,该物体在图像传感器上形成的像最为清晰。通过比较不同焦点位置下的图像清晰度,可以确定物体与相机之间的距离。
实现代码
* This program reconstructs the height of a single solder
* ball on a BGA using depth from focus.
*
dev_update_off ()
dev_close_window ()
read_image (Image, 'dff/focus_bga_37')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_paint ('default')
dev_display (Image)
*
* Read the sequence of images
disp_message (WindowHandle, 'Read a sequence of focus images ...', 'image', 20, 20, 'white', 'false')
Sequence := [37:-1:1]
Names := 'dff/focus_bga_' + Sequence$'02'
read_image (ImageArray, Names)
channels_to_image (ImageArray, Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
for Index := 1 to 37 by 1
access_channel (Image, ImageDisp, Index)
dev_display (ImageDisp)
disp_message (WindowHandle, 'DFF sequence of solder ball: image ' + Index$'02', 'image', 20, 20, 'white', 'false')
wait_seconds (0.05)
endfor
*
* Compute the depth map and display results
dev_display (ImageDisp)
disp_message (WindowHandle, 'Compute the depth map', 'image', 20, 20, 'white', 'false')
depth_from_focus (Image, Depth, Confidence, ['bandpass',3,3], 'next_maximum')
scale_image_max (Depth, DepthScaleMax)
select_grayvalues_from_channels (Image, Depth, Sharp)
scale_image (Sharp, ImageScaled, 8, 0)
compose2 (DepthScaleMax, ImageScaled, MultiChannelImage)
dev_clear_window ()
dev_set_paint (['3d_plot','texture'])
dev_display (MultiChannelImage)
disp_message (WindowHandle, '3D reconstruction of a solder ball on a bga', 'image', 20, 280, 'white', 'false')