基于kalman滤波器的背景估计,用于运动目标检测
* 不更新显示dev_update_off ()
* 关闭当前窗口
dev_close_window ()
* 读取图像
read_image (Image, 'xing/init')
get_image_size (Image, Width, Height)
* 新建一个图形窗口
dev_open_window (0, 0, Width, Height, 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
* 加载一个默认的区域
read_region (XingRegion, 'xing/xing_region')
* 以轮廓显示
dev_set_draw ('margin')
dev_set_colored (12)
dev_set_line_width (3)
dev_display (Image)
* 显示提示信息【Press Run(F5) to continue】
disp_continue_message (WindowID, 'black', 'true')
stop ()
* 图像缩小一倍
zoom_image_factor (Image, ImageZoomed, 0.5, 0.5, 'constant')
* 初始化一个背景估计矩阵
create_bg_esti (ImageZoomed, 0.7, 0.7, 'fixed', 0.001, 0.03, 'on', 8.0, 10, 3.25, 15, BgEstiHandle)
for I := 0 to 587 by 1
* 读取当前图像
read_image (ActualImage, 'xing/xing' + (I $ ‘’03'))
zoom_image_factor (ActualImage, ImageZoomed, 0.5, 0.5, 'constant')
* 由背景信息,获取感兴趣目标信息
run_bg_esti (ImageZoomed, ForegroundRegion, BgEstiHandle)
zoom_region (ForegroundRegion, RegionZoom, 2, 2)
* 交集
intersection (RegionZoom, XingRegion, RegionIntersection)
* 连通域操作,选择面积20-99999大小的区域
connection (RegionIntersection, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 20, 99999)
* 选择凸多边形区域
shape_trans (SelectedRegions, RegionTrans, 'convex')
union1 (RegionTrans, RegionUnion)
connection (RegionUnion, FinalConnected)
* 选择区域灰度值方差在25-1000范围内的目标区域
select_gray (FinalConnected, ActualImage, SelectedRegionsGray, 'deviation', 'and', 25, 1000)
union1 (SelectedRegionsGray, RegionUnionFinal)
* 形态学操作
dilation_rectangle1 (RegionUnionFinal, RegionDilation, 5, 5)
complement (RegionDilation, BackGround)
clip_region (BackGround, RegionClipped, 0, 0, Height - 1, Width - 1)
zoom_region (RegionClipped, BackGroundZoom, 0.5, 0.5)
* 更新背景估计矩阵
update_bg_esti (ImageZoomed, BackGroundZoom, BgEstiHandle)
shape_trans (SelectedRegionsGray, Rects, 'rectangle1')
dev_display (ActualImage)
dev_display (Rects)
endfor
give_bg_esti (BackgroundImage, BgEstiHandle)
dev_display (BackgroundImage)
close_bg_esti (BgEstiHandle)
dev_set_draw ('fill')
dev_update_on ()
页:
[1]