The OpenCV Video Surveillance / Blob Tracker Facility

本文档详细介绍了OpenCV视频监控设施的工作原理和技术细节,重点阐述了前景背景判别算法,并提供了混合高斯模型等实现方式的参数配置说明。

Unofficial Documentation

 

This is an attempt to document the OpenCV Video Surveillance facility.

  • It is at the moment, just a collection of insights from working with the under-documented code, and not a complete full documentation. In fact, at the moment this document will only focus on the Foreground / Background Discrimination part of the complete algorithm. Please feel free to add more details, improve the layout and edit the contents. (AdiShavit)

The OpenCV "Video Surveillance" facility, also called "blob tracker" through much of the code, is a simple but practical facility intended to track moving foreground objects against a relatively static background. Conceptually it consists of a three-stage video processing pipeline:

  1. A foreground/background discriminator which labels each pixel as either foreground or background.
  2. A blob detector which groups adjacent "foreground" pixels into blobs, flood-fill style.
  3. A blob tracker which assigns ID numbers to blobs and tracks their motion frame-to-frame.

Almost all the sophistication (and CPU time!) in this facility is devoted to the first stage, which uses a state of the art (as of 2003) algorithm. The other two stages use relatively unsophisticated algorithms. This has the advantage of making the module fast and quite generic.

More specialized applications will typically go on to use sophisticated algorithms to classify the blobs and perhaps extract six-degree-of-freedom orientation information from them using domain-specific object models. The basic module provided does not do this, but may be used as a jumping-off point to develop such a system, for example by using the OpenCV Haar-based routines to classify the blobs.

The foreground/background discrimination stage is both memory and CPU intensive. It builds and maintains a histogram-based statistical model of the video image background on a per-pixel basis; consequently it may easily wind up using on the loose order of a gigabyte of ram to process a TV-resolution video stream. (This may sound like gross overkill. It is not. Vision is a hard problem. It seems deceptively easy only because humans come with extraordinarily good subconscious vision logic built in. Computers are not so lucky.)

Resource consumption may be controlled via a number of tuning parameters. In general, the results obtained do not depend too critically upon the parameter settings; the casual user can (and probably should) simply leave them at their default settings.

The casual user can simply treat the module as a black box which translates a video stream into a list of moving blobs. At this level, the sample program samples/c/blobtrack.cpp included with the OpenCV source distribution may be used as-is or lightly tweaked, or equivalent code may be written using (say) the OpenCV Python or Matlab bindings. A Linux-based Gtk wrapper in C is available here. A "beta" documentation of these modules can be found on the SVN: doc/vidsurv/Blob_Tracking_Modules.doc

To build more sophisticated computer vision applications you will need to understand and extend the detailed internal structure of this facility, which actually involves six major video pipeline processing stages, each of which in general is implemented by several alternative modules offering different space/time/complexity tradeoffs, each alternative module having its own set of tuning parameters.

An article providing a good overview of the complete facility internal architecture may be found here:

 

Foreground / Background Segmentation

 

The implementation provides a choice of two modules for this subtask:

  1. CV_BG_MODEL_FGD

  2. CV_BG_MODEL_MOG

 

CV_BG_MODEL_FGD

 

The most sophisticated (and default) module is based on an algorithm from Foreground Object Detection from Videos Containing Complex Background, Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian, ACM MM2003 9p, available here (pdf).

Internally (in cvbgfg_acmmm2003.cpp) it uses a change-detection algorithm from: P.Rosin, Thresholding for Change Detection, ICCV, 1998, available here (pdf).

Parameters for this module are supplied via the CvFGDStatModelParams struct:

 

typedef struct CvFGDStatModelParams
{
    int    Lc;                  /* Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.                               */
    int    N1c;                 /* Number of color vectors used to model normal background color variation at a given pixel.                    */
    int    N2c;                 /* Number of color vectors retained at given pixel.  Must be > N1c, typically ~ 5/3 of N1c.                     */
                                /* Used to allow the first N1c vectors to adapt over time to changing background.                               */

    int    Lcc;                 /* Quantized levels per 'color co-occurrence' component.  Power of two, typically 16, 32 or 64.                 */
    int    N1cc;                /* Number of color co-occurrence vectors used to model normal background color variation at a given pixel.      */
    int    N2cc;                /* Number of color co-occurrence vectors retained at given pixel.  Must be > N1cc, typically ~ 5/3 of N1cc.     */
                                /* Used to allow the first N1cc vectors to adapt over time to changing background.                              */

    int    is_obj_without_holes;/* If TRUE we ignore holes within foreground blobs. Defaults to TRUE.                                           */
    int    perform_morphing;    /* Number of erode-dilate-erode foreground-blob cleanup iterations.                                             */
                                /* These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.                        */

    float  alpha1;              /* How quickly we forget old background pixel values seen.  Typically set to 0.1                                */
    float  alpha2;              /* "Controls speed of feature learning". Depends on T. Typical value circa 0.005.                               */
    float  alpha3;              /* Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.                         */

    float  delta;               /* Affects color and color co-occurrence quantization, typically set to 2.                                      */
    float  T;                   /* "A percentage value which determines when new features can be recognized as new background." (Typically 0.9).*/
    float  minArea;             /* Discard foreground blobs whose bounding box is smaller than this threshold.                                  */

}
CvFGDStatModelParams; 

 

This is initialized with the defaults:

 

/* default paremeters of foreground detection algorithm */
#define  CV_BGFG_FGD_LC              128
#define  CV_BGFG_FGD_N1C             15
#define  CV_BGFG_FGD_N2C             25

#define  CV_BGFG_FGD_LCC             64
#define  CV_BGFG_FGD_N1CC            25
#define  CV_BGFG_FGD_N2CC            40

/* BG reference image update parameter */
#define  CV_BGFG_FGD_ALPHA_1         0.1f

/* stat model update parameter
   0.002f ~ 1K frame(~45sec), 0.005 ~ 18sec (if 25fps and absolutely static BG) */
#define  CV_BGFG_FGD_ALPHA_2         0.005f

/* start value for alpha parameter (to fast initiate statistic model) */
#define  CV_BGFG_FGD_ALPHA_3         0.1f

#define  CV_BGFG_FGD_DELTA           2

#define  CV_BGFG_FGD_T               0.9f

#define  CV_BGFG_FGD_MINAREA         15.f

#define  CV_BGFG_FGD_BG_UPDATE_TRESH 0.5f

 

If we want to update alpha2, the paper explains:

  • If we think that n frames for the system to response to an “once-off” background change is quick enough, we should choose the learning rate alpha2 from (22):

    • (22) alpha2 > 1 - (1 - T)^(1/n)

    As example, if we want the system to response to an ideal "once-off" background change after 20 seconds with 25 fps frame rate and T = 90%, alpha2 should be larger than 0.0046 but not too larger than it to prevent the system not to sensitive to noise and foreground objects. So:

       n = 20*25 = 500 
       T = 0.9
       => 0.005f = CV_BGFG_FGD_ALPHA_2 = alpha2 > 1 - ((1 - 0.9)^(1 / 500)) = 0.00459458265 

    T is a percentage value which determines when the new features can be recognized as new background appearance. With a large value of T, the system is stable but slow to response to the "once-off" changes. However, if T is small, the system is easy to learn the frequent foreground features as new background appearances. In our tests, T was set as 90%.

 

CV_BG_MODEL_MOG

 

This is an implementation of the Mixture of Gaussians paper: P. KadewTraKuPong and R. Bowden,An improved adaptive background mixture model for real-time tracking with shadow detection, in Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001. It can be foundhere (pdf)(citeceer).

 

just a comment

 

Due to the complexity of the process and lack of documentation, the following link may be quite helpful in understanding all the necessary steps. http://www.merl.com/papers/docs/TR2003-36.pdf

 

Example

 

 

Blob Entrance Detection

 

The “Blob Entering Detection” module uses the result (FG mask) of the “FG/BG Detection” module to detect that a new blob object enters the scene.

Actually, two implementations exist for this module:

  1. BD_CC - Detect new blob by tracking connected components of ForeGround mask

  2. BD_Simple - Detect new blob by uniform moving of connected components of FG mask

The execution is similar for both, using the background model explained above we can resume the call of this module by:

 

#include "cvaux.h"

IplImage *current_frame;
int nextBlobID=1;
CvBlobSeq* newBlobList, CvBlobSeq* blobList;
CvBGStatModel* bgModel = cvCreateGaussianBGModel(cvQueryFrame(capture),NULL);
CvBlobDetector* blobDetect = cvCreateBlobDetectorCC(); //or cvCreateBlobDetectorSimple();
...
while(cvGrabFrame(capture)) {

      //Compute the FG
     current_frame = cvRetrieveFrame(capture);
     cvUpdateBGStatModel(current_frame,bgModel);

    ....

     //Then once the BG is trained use FG to detect new blob.
    if(FrameCount > FGTrainFrames) {
        
        blobDetect->DetectNewBlob(current_frame, bgModel->foreground, &newBlobList, &blobList);

        //Loop on the new blob found.
        for(i=0; i<newBlobList.GetBlobNum(); ++i)
        {
            CvBlob* pBN = NewBlobList.GetBlob(i);
            pBN->ID = nextBlobID;

            //Check if the size of the new blob is big enough to be inserted in the blobList.
            if(pBN && pBN->w >= CV_BLOB_MINW && pBN->h >= CV_BLOB_MINH)
            {
                   cout << "Add blob #" << nextBlobID << endl; 
                   blobList.AddBlob(pBN);
                   nextBlobID++;                  
            }
        }
    }

    //Then a tracking should be performed to follow the blob
    ...  
}

 

This code is a simplification of the code in "cvaux/vs/blobtrackingauto.cpp"

采用PyQt5框架与Python编程语言构建图书信息管理平台 本项目基于Python编程环境,结合PyQt5图形界面开发库,设计实现了一套完整的图书信息管理解决方案。该系统主要面向图书馆、书店等机构的日常运营需求,通过模块化设计实现了图书信息的标准化管理流程。 系统架构采用典型的三层设计模式,包含数据存储层、业务逻辑层和用户界面层。数据持久化方案支持SQLite轻量级数据库与MySQL企业级数据库的双重配置选项,通过统一的数据库操作接口实现数据存取隔离。在数据建模方面,设计了包含图书基本信息、读者档案、借阅记录等核心数据实体,各实体间通过主外键约束建立关联关系。 核心功能模块包含六大子系统: 1. 图书编目管理:支持国际标准书号、中国图书馆分类法等专业元数据的规范化著录,提供批量导入与单条录入两种数据采集方式 2. 库存动态监控:实时追踪在架数量、借出状态、预约队列等流通指标,设置库存预警阈值自动提醒补货 3. 读者服务管理:建立完整的读者信用评价体系,记录借阅历史与违规行为,实施差异化借阅权限管理 4. 流通业务处理:涵盖借书登记、归还处理、续借申请、逾期计算等标准业务流程,支持射频识别技术设备集成 5. 统计报表生成:按日/月/年周期自动生成流通统计、热门图书排行、读者活跃度等多维度分析图表 6. 系统维护配置:提供用户权限分级管理、数据备份恢复、操作日志审计等管理功能 在技术实现层面,界面设计遵循Material Design设计规范,采用QSS样式表实现视觉定制化。通过信号槽机制实现前后端数据双向绑定,运用多线程处理技术保障界面响应流畅度。数据验证机制包含前端格式校验与后端业务规则双重保障,关键操作均设有二次确认流程。 该系统适用于中小型图书管理场景,通过可扩展的插件架构支持功能模块的灵活组合。开发过程中特别注重代码的可维护性,采用面向对象编程范式实现高内聚低耦合的组件设计,为后续功能迭代奠定技术基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
《基于SSM架构的学籍数据管理平台技术解析》 在当代数字化教育背景下,数据管理平台已成为教育机构运营的核心支撑。本系统以SSM技术组合为基础架构,构建了一套完整的学籍信息处理体系,通过系统化的技术方案实现教育数据的规范化管理与智能分析。以下从架构设计、技术实现与功能模块三个维度展开说明。 一、系统架构设计 该平台采用分层式架构设计,充分体现模块化与可维护性特征。Spring框架作为核心容器,通过依赖注入机制实现组件解耦;SpringMVC架构负责前端请求的路由与响应处理;MyBatis数据层框架则封装了数据库交互过程,通过映射配置简化SQL操作。三层架构协同工作,形成高内聚低耦合的技术体系。 二、技术实现要点 1. Spring容器:基于控制反转原则管理业务对象生命周期,结合面向切面编程实现事务控制与日志管理 2. SpringMVC模块:采用模型-视图-控制器设计范式,规范Web层开发流程,支持RESTful接口设计 3. MyBatis组件:通过XML配置实现对象关系映射,提供动态SQL生成机制,显著减少冗余编码 三、核心功能模块 1. 学籍信息维护:实现学员基本资料的增删改查操作,涵盖学籍编号、个人信息、所属院系等关键字段 2. 学业成绩管理:支持课程分数录入与批量处理,提供多维度统计分析功能 3. 教学组织管理:建立班级体系与学员关联关系,实现分级数据管理 4. 权限控制机制:基于角色访问控制模型,划分管理员、教职工、学员三级操作权限 5. 系统审计功能:完整记录用户操作轨迹,构建安全追踪体系 四、系统开发方法论 在项目生命周期中,采用结构化开发流程。前期通过需求调研确定系统边界,中期完成数据库范式设计与接口规范制定,后期采用迭代开发模式配合自动化测试,确保系统交付质量。 五、技术演进展望 当前系统虽未集成智能算法,但为未来升级预留了扩展接口。可预见的技术演进方向包括:基于学习行为数据的智能预警、个性化学习路径推荐等深度应用场景。 综上所述,该平台通过SSM技术体系实现了教育管理数据的标准化处理,既展示了现代软件开发范式的实践价值,也为教育信息化建设提供了可复用的技术方案。这种系统化的问题解决思路,充分体现了软件工程方法在教育领域的应用潜力。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值