卡尔曼滤波器的一个应用。
create_bg_esti (ImageZoomed, 0.7, 0.7, 'fixed', 0.001, 0.03, 'on', 8.0, 10, 3.25, 15, BgEstiHandle)
* create_bg_esti(InitializeImage : : Syspar1, Syspar2, GainMode, Gain1, Gain2, AdaptMode,
*MinDiff, StatNum, ConfidenceC, TimeC : BgEstiHandle)
*InitializeImage用作背景图像的初始预测。对于一个很好的预测,没有移动物体的观察场景的图像应该在
*InitializeImage中传递。这样前景适应率就可以保持在较低水平。如果没有空的场景图像可用,则可以使用均
*匀的灰度图像代替。在这种情况下,前景图像的自适应率必须提高,因为最初的大部分图像将被检测为前景。初
*始化映像必须是字节类型或实数类型。由于处理单通道图像,必须为每个通道创建数据集。InitializeImage的
*大小和区域决定了使用该数据集执行的所有背景估计(run_bg_esti)的大小和区域。
read_image (ActualImage, 'xing/xing' + (I$'03'))
zoom_image_factor (ActualImage, ImageZoomed, 0.5, 0.5, 'constant')
run_bg_esti (ImageZoomed, ForegroundRegion, BgEstiHandle)
*run_bg_esti(PresentImage : ForegroundRegion : BgEstiHandle : )
*run_bg_esti对每个像素使用卡尔曼滤波器来调整存储在BgEsti数据集中的背景图像,并返回前景的一个区域
*(检测到的移动物体)。对于每个像素,使用当前数据集及其存储的背景图像和当前图像(PresentImage)的值
*计算其灰度值的估计。通过与阈值(固定或自适应,参见create_bg_esti)的比较,像素被分类为前景或背
*景。背景估计只处理单通道图像。因此,背景必须分别适应每个通道。背景估计应该用于一半或甚至四分之一
*大小的图像。为此,必须使用zoom_image_factor减少输入图像(和初始化图像!)。优点一方面是运行时间较
*短,另一方面是低频带滤波。该滤波消除了高频噪声,使估计更加可靠。因此可以降低阈值(参见
*create_bg_esti)。然后,run_bg_esti返回的前景区域必须再次放大以进行进一步处理。
zoom_region (ForegroundRegion, RegionZoom, 2, 2)
intersection (RegionZoom, XingRegion, RegionIntersection)
connection (RegionIntersection, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 20, 99999)
shape_trans (SelectedRegions, RegionTrans, 'convex')
union1 (RegionTrans, RegionUnion)
connection (RegionUnion, FinalConnected)
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')
前景和背景的区分,可以参看以下代码,设定好背景(create_bg_esti)后,用run_bg_esti()函数来找到前景区。
* Read image for initialization:
read_image(InitImage,'xing/init')
* Initialize BgEsti dataset with
* fixed gains and threshold adaption:
create_bg_esti(InitImage,0.7,0.7,'fixed',0.002,0.02, \
'on',7.0,10,3.25,15.0,BgEstiHandle)
* Read the next image in sequence:
read_image(Image0,'xing/xing000')
* Estimate the background:
run_bg_esti(Image0,ForegroundRegion1,BgEstiHandle)
* Display the foreground region:
dev_display (ForegroundRegion1)
* Read the next image in sequence:
read_image(Image1,'xing/xing001')
* Estimate the background:
run_bg_esti(Image1,ForegroundRegion2,BgEstiHandle)
* Display the foreground region:
dev_display (ForegroundRegion2)
* etc.
看着准确性并不是太高,这类问题可能更适合深度学习目标检测的方法
背景图片。
检测后图片