OpenCV温故而知新: 遺失物偵測

函式功能规格

全域类别说明:

class CLostDetect{

private:

int         nAlarmFlag         ;                    //警告之flag

int         nWidth, nHeight ;                    //Frame之宽高

int         nAlarmTimer              ;                    //警告时间

 

bool      bEgdeDen           ;                    //edge density的变数

bool      bObjectSetted            ;                    //侦测物是否设定

int         nHdims               ;                    //Histogram维度变数

float      pHranges_arr[2]  ;                    //Histogram范围大小

float      *pHranges           ;

CvRect cvRectObjectWinodw       ;             //设定选取对象之框的变量

CvHistogram *pRHist                   ;             //计算R & G & B之histogram

CvHistogram *pGHist                    ;

CvHistogram *pBHist                    ;

IplImage *pCurFrame                            ;     //input image

IplImage *pGray                             ;      //color to gray

IplImage *pEdge                                 ;      //edge image

IplImage *pObjectImageModel            ;      //for rotate 0

IplImage *pObjectImageModel1          ;      //for rotate 15 degree

IplImage *pObjectImageModelMinus1       ;      //for rotate-15 degree

public:

CLostDetect(int width, int height, int alarmerTimer);                            //建构子

~CLostDetect();                                                                        //解构子

bool Reset() { bObjectSetted = false; return true;};                  //把bObjectSetted设为false

bool SetImage(BYTE* pImageArray);                                             //承接AP所传入的变量型态

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

bool SetObject(IplImage *pImage, int x, int y, int width, int height);

//设定object model

int   GetObjectState();                                                               //计算edge density

bool Alarm() {return (nAlarmFlag>nAlarmTimer); };               //send alarm message

};

成员函式说明:

CLostDetect::CLostDetect(int width, int height, int nSeconds=5){

Purpose: initial all variables we’ll use the program

Usage: set all variable will use.

Parameter:

Parameter

Type

Description

width

int

the width of frame

height

int

the height of frame

nSeconds

int

alarm time set to 5

}

CLostDetect::~CLostDetect(){

Purpose: release variables

release all image variables

release both Hist variables

}

bool CLostDetect::SetImage(BYTE* pImageArray){

Purpose: Succeed to AP’s package to IplImage data type variable.

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

Parameter:

Parameter

Type

Description

pImageArray BYTE Succeed input data type

Return:

True, if success

False, otherwise

}

bool CLostDetect::SetImage(IplImage *pImage){

Purpose: detect whether the lost 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

}

bool CLostDetect::SetObject(IplImage *pImage, int x, int y, int width, int height){

Purpose: set the object model.

Usage: given image frame, object position, width and height, return bool variable.

Parameter:

Parameter

Type

Description

pImage

IplImage

input image variable

x

int

Position of x

y

int

Position of y

width

int

Width of frame

height

int

Height of frame

Return:

True, if success

False, otherwise

}

int CLostDetect::GetObjectState(){

Purpose: After setting object model, quantify the object model edge density.

Usage: compute the edge density of object model.

Return:

0 when the procedure finished

}

测试程序及序列

测试程序: http://rg4.net/p/easyiv/liblostdetect_test.7z。测试程序快捷键:按r重新设定ROI检测区域,按p暂停处理,按t中止。

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

 

Author: Jacky Wei

I am a programmer, welcome to my blog: http://rg4.net.

Leave a Reply

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