OpenCV温故而知新: 画面遮蔽功能实现 2


应用场景

画面遮蔽侦测主要应用于一些强制性开放的视频地点,如:煤矿矿产区,或者是一些特定的娱乐场所,这些视频在一些时候通常是要作为“现场证据”来呈现的,而有人的却可能由于各种原因,不想让视频给录下来…这个模块的目标就是检测出画面遮蔽,并告警通知相关人员去进行必要的处理。

工作原理

先将视频进行灰度处理,然后进行背景、前景差检测画面的差异,并检测差异部分是否是大片连续的,若是则认为画面被遮蔽。

补充说明

由于本算法对其应用场景有一定的特殊要求,若是放到不太合适的地方容易出现许多误报的状况。

以下是接口说明。

函式功能规格说明

全域类别说明

class CMaliciousDetect{

private:

bool bAlarmFlag;                                   //发出警告的bool variable

int nAlarmTimer;                             //警告时间

int nWidth, nHeight;                       //Frame之宽高

bool IsSetted;                                         //background是否设定变量

IplImage *Frame;                                   //input image

IplImage *Gray;                             //把input image转换成gray level

IplImage *C_edge;                       // The edge value image

IplImage *BG_edge;

IplImage *_small;                                //resize C_edge to _small

IplImage *BG_small;                            //       BG_edge to _small

CvHistogram *BG_hist,*C_hist;          //计算histogram for 变量BG_hist & C_hist

int hist_size ;                                         //设histogram之纵轴范围

CvScalar  num1 , num2 ;                     //计算BG_small&_small的edge value

int WCount;                                          //出现warning的时间变量

int OCount;                                     //发生状况一的遮蔽,计算秒数的变量

int ECount;                                     //发生状况二的遮蔽,计算秒数的变量

int HCount;                                     //发生状况三的遮蔽,计算秒数的变变

int H_HT ;                                       //histogram high and low threshold

int H_LT ;

double HistDiff;                                   //the difference of BG_hist & C_hist

public:

CMaliciousDetect( int nImageWidth, int nImageHeight, int nSeconds );  //建构子

~CMaliciousDetect();                                                                        //解构子

bool SetImage(BYTE *pImageArray);  //由AP承接image package

bool SetImage(IplImage *pImage);       //Whole algorithm

bool Alarm() {return bAlarmFlag;};      //send the alarm information

void ResetSystem() {IsSetted = false;};//判断是否已经设定background

};

成员函式说明:

CMaliciousDetect::CMaliciousDetect(int nImageWidth, int nImageHeight, int nSeconds){

Purpose:initial image variables and Hist variables.

Usage :set all variable will use.

Parameter:

Parameter Type Description
nImageWidth int the width of frame
nImageHeight int the height of frame
nSeconds int alarm time

}

CMaliciousDetect::~CMaliciousDetect(){

Purpose:release variables

release all image variables

release both Hist variables

}

bool CMaliciousDetect::SetImage(BYTE* pImageArray){

Purpose: Succeed to AP’s package.

Usage: While webcam give image data into the program, check it data type.

Parameter:

Parameter

Type

Description

pImageArray BYTE input data type

Return:

True, if success

False, otherwise

}

bool CMaliciousDetect::SetImage(IplImage *pImage){

Purpose: detect whether the occlusion happened.

Usage: While AP given the right data type, starting the algorithm of detection

Parameter

Parameter

Type

Description

PImage IplImage If the input data is not NULL, starting to go the process

Return:

True, if success

False, otherwise

}

测试程序及序列

测试程序: http://rg4.net/p/easyiv/libmaliciousdetect_test.7z

测试视频序列:http://rg4.net/p/easyiv/libmaliciousdetect_sample.7z


Leave a Reply to chieh Cancel reply

Your email address will not be published. Required fields are marked *

2 thoughts on “OpenCV温故而知新: 画面遮蔽功能实现

  • chieh

    Jacky Wei 您好:

    敝人最近也在從事這類研究,
    是否方便跟您請教
    “畫面遮蔽” 的相關原理及演算法(algorithm)

    假若您不介意
    亦希望能取得本專案的Source Code
    作為研究開發參考

    感謝您

  • Jacky Wei Post author

    chieh,非常抱歉,source code由于涉及版权,我不能提供给你。你的前一封mail讲畫面遮蔽我以为是要故意遮蔽画面中的某一部位(如:遮蔽ATM机的输密码区,以避免将用户输密码的过程也录进录像)。但看来你是要检测画面遮蔽,我已经将这篇文章做了一点补充,有将其实现原理加上,这样,若是你熟悉OpenCV的话,应该可以很容易就能自己写出代码,详请参考本文中的“工作原理”。

    BTW:若是你有研究其它的一些OpenCV的算法,或者是具体的OpenCV的某一功能,我们可以一起交流和探讨,但若是这些我原公司的算法的source code,抱歉,实在不行。