# 背景减除

背景减除是一种面向固定摄像机的计算机视觉技术，它维护场景背景的统计模型，并将每一输入帧的每个像素标记为前景或背景，生成二值掩膜，供下游的跟踪、检测和分类使用。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup> 每个视频帧与背景模型进行比较，强度值显著偏离背景模型的像素被标记为前景。<sup>[2](https://www.researchgate.net/publication/313111384_Review_of_background_subtraction_methods_using_Gaussian_mixture_model_for_video_surveillance_systems)</sup> 该技术假设摄像机静止，是一种在线操作，分为两个阶段：背景初始化（引导模型）和背景维护或更新。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup>

| 关键事实 | 值 |
|---|---|
| 输出 | 8 位二值前景掩膜，每帧每像素一个标签；检测到的阴影可单独编码（OpenCV 中为 127）<sup>[3](https://docs.opencv.org/5.0/main_modules/classcv_1_1BackgroundSubtractorMOG2.html)</sup><sup> • </sup><sup>[4](https://docs.opencv.org/4.10.0/d1/dc5/tutorial_background_subtraction.html)</sup> |
| 核心分类规则 | 若 \( d(I_{s,t}, B_{s}) > \tau \)，则 \( X_{t}(s) = 1 \)，否则为 0<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup> |
| 典型模型 | 逐像素的 \( K \) 个高斯混合，\( K \) 通常为 3 至 5，匹配阈值在 2.5 个标准差以内<sup>[6](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)</sup> |
| OpenCV MOG2 默认值 | history = 500（学习率 \( \alpha = 1/500 \)），varThreshold = 16，5 个混合成分，背景比例 0.9<sup>[7](https://github.com/opencv/opencv/blob/4.x/modules/video/src/bgfg_gaussmix2.cpp)</sup> |
| 标准基准 | CDnet 2014：53 个视频，11 个类别，320×240 至 720×526 像素，七项指标<sup>[8](https://openaccess.thecvf.com/content/WACV2026/papers/Huang_SeqFeedNet_Sequential_Feature_Feedback_Network_for_Background_Subtraction_WACV_2026_paper.pdf)</sup> |
| 速度范围 | ViBe 在 CDnet 2014 上约 200 fps；高斯混合跟踪器在 SGI O2 上以 160×120 分辨率运行时为 11 至 13 fps<sup>[9](https://mdpi-res.com/d_attachment/jimaging/jimaging-06-00050/article_deploy/jimaging-06-00050-v2.pdf?version=1593403075)</sup><sup> • </sup><sup>[10](http://www.ai.mit.edu/projects/vsam/Tracking/index.html)</sup> |
| CDnet 2014 上最佳有监督 F 值 | 高于 0.97（FgSegNet 及其变体）<sup>[11](https://www.mdpi.com/2624-6120/7/1/14)</sup> |

## 工作原理

所有背景减除方法共享同一条分类规则：时刻 \( t \) 的像素 \( s \)，当其值与背景模型的偏差超过阈值 \( \tau \) 时为前景，即若 \( d(I_{s,t}, B_{s}) > \tau \) 则 \( X_{t}(s) = 1 \)；方法之间的差异主要在于 \( B \) 的建模方式以及所用距离 \( d \) 的不同。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup> 最简单的模型是滑动平均，按 \( B_{s,t+1} = (1-\alpha) \cdot B_{s,t} + \alpha \cdot I_{s,t} \) 更新，其中 \( \alpha \) 介于 0 和 1 之间。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup>

主流的参数化模型是逐像素高斯混合：\( P(I_{s,t}) = \sum_{i=1}^{K} \omega_{i,s,t} \cdot \eta(I_{s,t}, \mu_{i,s,t}, \Sigma_{i,s,t}) \)，其中 \( K \) 通常为 3 至 5。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup><sup> • </sup><sup>[6](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)</sup> 匹配的分量在线更新，权重按 \( \omega_{k,t} = (1-\alpha) \cdot \omega_{k,t-1} + \alpha \cdot M_{k,t} \) 更新（其中 \( M_{k,t} \) 在匹配模型上取 1，\( \alpha \) 为学习率），匹配均值按 \( \mu_{t} = (1-\rho) \cdot \mu_{t-1} + \rho \cdot X_{t} \) 更新；当没有分量匹配时，替换权重最低的分量。<sup>[6](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)</sup><sup> • </sup><sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup> 当最佳匹配的高斯分量合计携带足够权重且属于背景集合时，该像素被分类为背景。<sup>[6](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)</sup>

学习率直接控制自适应速度：在 OpenCV 的 MOG2 中，0 表示模型完全不更新，1 表示完全从最后一帧重新初始化，负值则选择自动速率。<sup>[3](https://docs.opencv.org/5.0/main_modules/classcv_1_1BackgroundSubtractorMOG2.html)</sup>

## 实现方式

实践中的流水线包含三个模块：背景初始化，从 \( N \) 个训练帧构建初始背景图像；前景检测，通过比较背景图像与当前图像对每个像素进行分类；背景维护，利用前一背景、当前图像和检测掩膜更新模型。<sup>[12](https://ar5iv.labs.arxiv.org/html/1901.03577)</sup> 在 OpenCV 中，这相当于用 cv::VideoCapture 读取帧，创建减除器（MOG2 或 KNN），并对每帧调用其 apply 方法，可选传入学习率；返回的掩膜即为前景图像。<sup>[4](https://docs.opencv.org/4.10.0/d1/dc5/tutorial_background_subtraction.html)</sup>

默认参数在很大程度上决定行为。OpenCV 的 createBackgroundSubtractorMOG2 默认值为 history = 500、varThreshold = 16、detectShadows = true；KNN 减除器默认 history = 500、dist2Threshold = 400.0。<sup>[4](https://docs.opencv.org/4.10.0/d1/dc5/tutorial_background_subtraction.html)</sup><sup> • </sup><sup>[7](https://github.com/opencv/opencv/blob/4.x/modules/video/src/bgfg_gaussmix2.cpp)</sup> 匹配阈值基于马氏距离的平方，默认值为 16，而 9 是生成新混合分量时使用的默认 varThresholdGen；<sup>[3](https://docs.opencv.org/5.0/main_modules/classcv_1_1BackgroundSubtractorMOG2.html)</sup> 若像素是背景的较暗版本，则报告为阴影（掩膜中灰度值为 127），Tau = 0.5 表示亮度低于背景一半的像素不算阴影。<sup>[3](https://docs.opencv.org/5.0/main_modules/classcv_1_1BackgroundSubtractorMOG2.html)</sup>

## 起源

最早的监控用背景减除采用固定摄像机相邻帧差分，但无法恢复完整的前景外观。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup> 随后出现了逐像素统计模型。Pfinder（雷恩（Wren）、阿扎尔巴耶贾尼（Azarbayejani）、达雷尔（Darrell）和彭特兰（Pentland），IEEE 模式分析与机器智能汇刊，1997）在 YUV 空间中以简单在线更新的均值对每个像素建模。<sup>[13](https://doi.org/10.1109/34.598236)</sup><sup> • </sup><sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup> 更早的交通监控方案用三个高斯分别对应道路、车辆和阴影来对每个像素建模。<sup>[14](https://hal.science/file/index/docid/338206/filename/RPCS_2008.pdf)</sup> [高斯混合模型](https://www.edgepedia.org/zh/gaussian-mixture-model)将其推广为每像素 \( K \) 个高斯，并采用在线 K 均值式更新。<sup>[6](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)</sup> 日夫科维奇（Zivkovic）的改进自适应高斯混合模型（2004）通过带负 Dirichlet 先验的 MAP 检验自动选择分量数量，正是 OpenCV 的 MOG2 所实现的算法。<sup>[7](https://github.com/opencv/opencv/blob/4.x/modules/video/src/bgfg_gaussmix2.cpp)</sup><sup> • </sup><sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup>

Wallflower（远山（Toyama）、克鲁姆（Krumm）及同事，1999）结合了像素级维纳滤波、区域级空洞填充和帧级模型切换，在物体被移位、一天中的时间变化、开关灯、树木摇曳和伪装等典型问题上优于其他 8 种算法。<sup>[15](http://robots.stanford.edu/cs223b04/BackgroundSubtractionMSResearch.pdf)</sup> 子空间模型随特征背景主成分分析（PCA）方法（奥利弗（Oliver）、罗萨里奥（Rosario）和彭特兰（Pentland），IEEE TPAMI，2000）出现。<sup>[16](https://doi.org/10.1109/34.868684)</sup> 非参数 Parzen 窗（核密度）估计则逐像素进行。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup>

## 变体

经典方法族在表示方式和更新策略上有所不同：<sup>[17](https://par.nsf.gov/servlets/purl/10481999)</sup>

- **滑动平均与滤波模型**：每像素保留单一背景值，例如低通基线 \( B_{t} = \alpha \cdot I_{t} + (1-\alpha) \cdot B_{t-1} \)。<sup>[18](https://doi.org/10.1109/tip.2010.2101613)</sup>
- **参数化模型**：单高斯（快速、低内存，但在复杂背景上失效）以及分量数固定或自动选择的高斯混合。<sup>[19](https://arxiv.org/pdf/1804.05459)</sup><sup> • </sup><sup>[7](https://github.com/opencv/opencv/blob/4.x/modules/video/src/bgfg_gaussmix2.cpp)</sup>
- **非参数模型**：逐像素核密度估计，内存开销较高。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup>
- **码本模型**（金（Kim）、查利达邦塞（Chalidabhongse）、哈伍德（Harwood）和戴维斯（Davis），Real-Time Imaging，2005）：使用颜色失真度量和亮度边界，为每像素维护压缩的码字集合；它能应对局部和全局光照变化，并允许训练期间存在移动前景物体。<sup>[20](https://doi.org/10.1016/j.rti.2004.12.004)</sup>
- **样本一致性方法**：ViBe（巴尼奇（Barnich）和范德罗根布鲁克（Van Droogenbroeck），IEEE 图像处理汇刊，2010）为每像素存储一组样本，不显式建立概率密度函数，若某值在半径内接近足够多的样本则分类为背景；其更新结合了无记忆策略、随机时间子采样和样本空间传播，其保守策略从不接纳前景样本，从而避免永久性鬼影。<sup>[18](https://doi.org/10.1109/tip.2010.2101613)</sup><sup> • </sup><sup>[21](https://orbi.uliege.be/bitstream/2268/12087/1/Barnich2009ViBe.pdf)</sup>
- **自组织与组合方法**：SOBS（马达莱娜（Maddalena）和彼得罗西诺（Petrosino），IEEE TIP，2008）使用自组织神经背景模型；<sup>[22](https://doi.org/10.1109/tip.2008.924285)</sup> IUTIS-5（比安科（Bianco）、乔卡（Ciocca）和斯凯蒂尼（Schettini），IEEE 进化计算汇刊，2017）通过遗传编程组合变化检测算法。<sup>[23](https://doi.org/10.1109/tevc.2017.2694160)</sup>
- **子空间方法**：主成分分析（PCA）、独立成分分析（ICA）、增量非负矩阵分解（NMF）和鲁棒张量变体将背景建模为低维子空间；在 Wallflower 数据集上，它们的总误差小于高斯模型，主要归因于开关灯序列。<sup>[24](https://hal.science/hal-00534555/file/RPCS_2009.pdf)</sup>

深度与语义方法如今构成又一个方法族。语义背景减除使 CDnet 2014 上五个最佳无监督算法的平均错误率最多降低 20%。<sup>[9](https://mdpi-res.com/d_attachment/jimaging/jimaging-06-00050/article_deploy/jimaging-06-00050-v2.pdf?version=1593403075)</sup> 有监督网络包括 FgSegNet 及其变体，在 CDnet 2014 上 F 值高于 0.97。<sup>[11](https://www.mdpi.com/2624-6120/7/1/14)</sup> ZBS（安（An）及同事，2023）构建了具有零样本检测能力的开放词汇实例级背景模型，在 CDnet 2014 上的 F 值比最先进的无监督方法高出 4.70%。<sup>[25](https://doi.org/10.48550/arxiv.2303.14679)</sup>

## 应用

部署文献涵盖视频监控、交通监控和海事监控；已发表文献未量化在人数统计或工业检测中的部署情况。在海事监控中，由于水体动态变化，作者倾向于多模态背景模型（MOG、日夫科维奇（Zivkovic）-海登（Heijden）高斯混合模型），白天使用 RGB、夜间使用红外，并辅以形态学处理和显著性检测，以抑制水体运动引起的误报。<sup>[12](https://ar5iv.labs.arxiv.org/html/1901.03577)</sup>

评估以 CDnet 2014 为中心，该数据集被称为该领域最全面的数据集：11 个类别共 53 个自然视频，分辨率 320×240 至 720×526，按召回率、特异性、假正率（FPR）、假负率（FNR）、变化像素百分比（PWC）、精确率和 F 值评分。<sup>[8](https://openaccess.thecvf.com/content/WACV2026/papers/Huang_SeqFeedNet_Sequential_Feature_Feedback_Network_for_Background_Subtraction_WACV_2026_paper.pdf)</sup> 在无约束室外监控中，最佳方法（SOBS）的 f 值约为 81%，各方法在野外场景中平均退化 11%，性能与场景野外程度呈负相关。<sup>[26](https://www.di.ubi.pt/~jcneves/assets/publications/ICSIPA_2015.pdf)</sup>

## 局限与替代方案

当背景减除关于摄像机严格固定、背景静止无噪声的假设被违反时，它就会失效：光照逐渐或突然变化、背景包含波浪或风吹树木等运动物体、摄像机抖动。<sup>[5](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)</sup> 在 CDnet 上，摄像机运动导致大量误报，夜间视频导致漏报，硬阴影对所有方法构成挑战，间歇运动的物体最终会被吸收进模型。<sup>[27](https://openaccess.thecvf.com/content_cvpr_workshops_2014/W12/papers/Wang_CDnet_2014_An_2014_CVPR_paper.pdf)</sup>

学习率体现了核心权衡：低学习率使混合模型易受开关灯问题影响，而自适应过快会吸收缓慢移动的前景像素，产生前景孔径问题和高漏报率。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup> 伪装问题通过形态学操作加入纹理或轮廓信息来解决；阴影问题通过逐像素 HSV 分析或阴影鲁棒的边缘信息来解决。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup> RGBD 传感器的深度信息可应对开关灯、光照渐变、前景阴影和颜色伪装，因为它对场景颜色和光照不敏感，颜色加深度的方法优于单独使用任一方法；当背景区域从未出现时，即使最佳初始化方法也会失败，只有图像修复等技术能恢复缺失数据。<sup>[28](https://www.mdpi.com/2313-433X/4/5/71)</sup> 比较研究一致认为，没有一种方法对所有挑战性场景都完美。<sup>[19](https://arxiv.org/pdf/1804.05459)</sup> ViBe 以精确率见长，但会漏检物体的部分区域；基于高斯的方法在静态阴影中表现最佳。<sup>[26](https://www.di.ubi.pt/~jcneves/assets/publications/ICSIPA_2015.pdf)</sup>

帧差分作为历史根源仍然存在，但无法恢复完整的前景外观。<sup>[1](https://link.springer.com/article/10.1155/2010/343057)</sup>

## References

1. [Background Subtraction for Automated Multisensor Surveillance: A Comprehensive Review (Cristani et al., 2010)](https://link.springer.com/article/10.1155/2010/343057)
2. [Review of background subtraction methods using Gaussian mixture model for video surveillance systems](https://www.researchgate.net/publication/313111384_Review_of_background_subtraction_methods_using_Gaussian_mixture_model_for_video_surveillance_systems)
3. [Class cv::BackgroundSubtractorMOG2, OpenCV documentation](https://docs.opencv.org/5.0/main_modules/classcv_1_1BackgroundSubtractorMOG2.html)
4. [How to Use Background Subtraction Methods, OpenCV Tutorials](https://docs.opencv.org/4.10.0/d1/dc5/tutorial_background_subtraction.html)
5. [Review and Evaluation of Commonly-Implemented Background Subtraction Algorithms (Benezeth et al., ICPR 2008)](https://inria.hal.science/inria-00545518/file/ICPR_2008.pdf)
6. [Adaptive background mixture models for real-time tracking (Stauffer & Grimson)](http://www.ee.unlv.edu/~b1morris/ecg795/docs/stauffer_cvpr98_track.pdf)
7. [opencv/modules/video/src/bgfg_gaussmix2.cpp, OpenCV source code](https://github.com/opencv/opencv/blob/4.x/modules/video/src/bgfg_gaussmix2.cpp)
8. [SeqFeedNet: Sequential Feature Feedback Network for Background Subtraction](https://openaccess.thecvf.com/content/WACV2026/papers/Huang_SeqFeedNet_Sequential_Feature_Feedback_Network_for_Background_Subtraction_WACV_2026_paper.pdf)
9. [Asynchronous Semantic Background Subtraction (ASBS), Journal of Imaging 2020](https://mdpi-res.com/d_attachment/jimaging/jimaging-06-00050/article_deploy/jimaging-06-00050-v2.pdf?version=1593403075)
10. [Tracking: Adaptive Background Mixture Models (MIT VSAM project page)](http://www.ai.mit.edu/projects/vsam/Tracking/index.html)
11. [Comparative Study of Supervised Deep Learning Architectures for Background Subtraction and Motion Segmentation on CDnet2014](https://www.mdpi.com/2624-6120/7/1/14)
12. [Background Subtraction in Real Applications: Challenges, Current Models and Future Directions (Sobral & Bouwmans, 2019)](https://ar5iv.labs.arxiv.org/html/1901.03577)
13. [C.R. Wren and colleagues (1997). Pfinder: real-time tracking of the human body. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/34.598236)
14. [Background Modeling using Mixture of Gaussians for Foreground Detection - A Survey (Bouwmans et al., 2008)](https://hal.science/file/index/docid/338206/filename/RPCS_2008.pdf)
15. [Wallflower: Principles and Practice of Background Maintenance (Toyama et al., 1999)](http://robots.stanford.edu/cs223b04/BackgroundSubtractionMSResearch.pdf)
16. [N.M. Oliver, B. Rosario, A.P. Pentland (2000). A Bayesian computer vision system for modeling human interactions. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/34.868684)
17. [A Survey of Efficient Deep Learning Models for Moving Object Segmentation](https://par.nsf.gov/servlets/purl/10481999)
18. [O Barnich, M Van Droogenbroeck (2010). ViBe: A Universal Background Subtraction Algorithm for Video Sequences. IEEE Transactions on Image Processing.](https://doi.org/10.1109/tip.2010.2101613)
19. [Comparative study of motion detection methods for video surveillance systems](https://arxiv.org/pdf/1804.05459)
20. [Kyungnam Kim and colleagues (2005). Real-time foreground–background segmentation using codebook model. Real-Time Imaging.](https://doi.org/10.1016/j.rti.2004.12.004)
21. [ViBe: A powerful random technique to estimate the background in video sequences (ICASSP 2009)](https://orbi.uliege.be/bitstream/2268/12087/1/Barnich2009ViBe.pdf)
22. [L. Maddalena, A. Petrosino (2008). A Self-Organizing Approach to Background Subtraction for Visual Surveillance Applications. IEEE Transactions on Image Processing.](https://doi.org/10.1109/tip.2008.924285)
23. [Simone Bianco, Gianluigi Ciocca, Raimondo Schettini (2017). Combination of Video Change Detection Algorithms by Genetic Programming. IEEE Transactions on Evolutionary Computation.](https://doi.org/10.1109/tevc.2017.2694160)
24. [Subspace Learning for Background Modeling: A Survey (Bouwmans, 2009)](https://hal.science/hal-00534555/file/RPCS_2009.pdf)
25. [An, Yongqi and colleagues (2023). ZBS: Zero-shot Background Subtraction via Instance-level Background Modeling and Foreground Selection. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2303.14679)
26. [Evaluation of Background Subtraction Algorithms for Human Visual Surveillance](https://www.di.ubi.pt/~jcneves/assets/publications/ICSIPA_2015.pdf)
27. [CDnet 2014: An Expanded Change Detection Benchmark Dataset](https://openaccess.thecvf.com/content_cvpr_workshops_2014/W12/papers/Wang_CDnet_2014_An_2014_CVPR_paper.pdf)
28. [Background Subtraction for Moving Object Detection in RGBD Data: A Survey (Bouwmans et al., 2018)](https://www.mdpi.com/2313-433X/4/5/71)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Computer vision › Vision methods and geometry › Motion analysis and optical flow

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/background-subtraction

English original: https://www.edgepedia.org/background-subtraction
