?? cvvidsurv.hpp
字號:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __CVVIDEOSURVEILLANCE_H__
#define __CVVIDEOSURVEILLANCE_H__
/* turn off the functionality until cvaux/src/Makefile.am gets updated */
//#if _MSC_VER >= 1200
#include <stdio.h>
#if _MSC_VER >= 1200 || defined __BORLANDC__
#define cv_stricmp stricmp
#define cv_strnicmp strnicmp
#elif defined __GNUC__
#define cv_stricmp strcasecmp
#define cv_strnicmp strncasecmp
#else
#error Do not know how to make case-insensitive string comparison on this platform
#endif
//struct DefParam;
struct CvDefParam
{
struct CvDefParam* next;
char* pName;
char* pComment;
double* pDouble;
double Double;
float* pFloat;
float Float;
int* pInt;
int Int;
char** pStr;
char* Str;
};
class CV_EXPORTS CvVSModule
{
private: /* internal data */
CvDefParam* m_pParamList;
char* m_pModuleTypeName;
char* m_pModuleName;
char* m_pNickName;
protected:
int m_Wnd;
public: /* constructor and destructor */
CvVSModule()
{
m_pNickName = NULL;
m_pParamList = NULL;
m_pModuleTypeName = NULL;
m_pModuleName = NULL;
m_Wnd = 0;
AddParam("DebugWnd",&m_Wnd);
}
virtual ~CvVSModule()
{
CvDefParam* p = m_pParamList;
for(;p;)
{
CvDefParam* pf = p;
p=p->next;
FreeParam(&pf);
}
m_pParamList=NULL;
if(m_pModuleTypeName)free(m_pModuleTypeName);
if(m_pModuleName)free(m_pModuleName);
}
private: /* internal functions */
void FreeParam(CvDefParam** pp)
{
CvDefParam* p = pp[0];
if(p->Str)free(p->Str);
if(p->pName)free(p->pName);
if(p->pComment)free(p->pComment);
cvFree((void**)pp);
}
CvDefParam* NewParam(char* name)
{
CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam));
memset(pNew,0,sizeof(CvDefParam));
pNew->pName = strdup(name);
if(m_pParamList==NULL)
{
m_pParamList = pNew;
}
else
{
CvDefParam* p = m_pParamList;
for(;p->next;p=p->next);
p->next = pNew;
}
return pNew;
};
CvDefParam* GetParamPtr(int index)
{
CvDefParam* p = m_pParamList;
for(;index>0 && p;index--,p=p->next);
return p;
}
CvDefParam* GetParamPtr(char* name)
{
CvDefParam* p = m_pParamList;
for(;p;p=p->next)
{
if(cv_stricmp(p->pName,name)==0) break;
}
return p;
}
protected: /* INTERNAL INTERFACE */
int IsParam(char* name)
{
return GetParamPtr(name)?1:0;
};
void AddParam(char* name, double* pAddr)
{
NewParam(name)->pDouble = pAddr;
};
void AddParam(char* name, float* pAddr)
{
NewParam(name)->pFloat=pAddr;
};
void AddParam(char* name, int* pAddr)
{
NewParam(name)->pInt=pAddr;
};
void AddParam(char* name, char** pAddr)
{
CvDefParam* pP = NewParam(name);
char* p = pAddr?pAddr[0]:NULL;
pP->pStr = pAddr?pAddr:&(pP->Str);
if(p)
{
pP->Str = strdup(p);
pP->pStr[0] = pP->Str;
}
};
void AddParam(char* name)
{
CvDefParam* p = NewParam(name);
p->pDouble = &p->Double;
};
void CommentParam(char* name, char* pComment)
{
CvDefParam* p = GetParamPtr(name);
if(p)p->pComment = pComment ? strdup(pComment) : 0;
};
void SetTypeName(char* name){m_pModuleTypeName = strdup(name);}
void SetModuleName(char* name){m_pModuleName = strdup(name);}
void DelParam(char* name)
{
CvDefParam* p = m_pParamList;
CvDefParam* pPrev = NULL;
for(;p;p=p->next)
{
if(cv_stricmp(p->pName,name)==0) break;
pPrev = p;
}
if(p)
{
if(pPrev)
{
pPrev->next = p->next;
}
else
{
m_pParamList = p->next;
}
FreeParam(&p);
}
}/* DelParam */
public: /* EXTERNAL INTERFACE */
char* GetParamName(int index)
{
CvDefParam* p = GetParamPtr(index);
return p?p->pName:NULL;
}
char* GetParamComment(char* name)
{
CvDefParam* p = GetParamPtr(name);
if(p && p->pComment) return p->pComment;
return NULL;
}
double GetParam(char* name)
{
CvDefParam* p = GetParamPtr(name);
if(p)
{
if(p->pDouble) return p->pDouble[0];
if(p->pFloat) return p->pFloat[0];
if(p->pInt) return p->pInt[0];
}
return 0;
};
char* GetParamStr(char* name)
{
CvDefParam* p = GetParamPtr(name);
return p?p->Str:NULL;
}
void SetParam(char* name, double val)
{
CvDefParam* p = m_pParamList;
for(;p;p=p->next)
{
if(cv_stricmp(p->pName,name) != 0) continue;
if(p->pDouble)p->pDouble[0] = val;
if(p->pFloat)p->pFloat[0] = (float)val;
if(p->pInt)p->pInt[0] = cvRound(val);
}
}
void SetParamStr(char* name, char* str)
{
CvDefParam* p = m_pParamList;
for(;p;p=p->next)
{
if(cv_stricmp(p->pName,name) != 0) continue;
if(p->pStr)
{
if(p->Str)free(p->Str);
p->Str = NULL;
if(str)p->Str = strdup(str);
p->pStr[0] = p->Str;
}
}
/* convert to double and set */
if(str)SetParam(name,atof(str));
}
void TransferParamsFromChild(CvVSModule* pM, char* prefix = NULL)
{
char tmp[1024];
char* FN = NULL;
int i;
for(i=0;;++i)
{
char* N = pM->GetParamName(i);
if(N == NULL) break;
FN = N;
if(prefix)
{
strcpy(tmp,prefix);
strcat(tmp,"_");
FN = strcat(tmp,N);
}
if(!IsParam(FN))
{
if(pM->GetParamStr(N))
{
AddParam(FN,(char**)NULL);
}
else
{
AddParam(FN);
}
}
if(pM->GetParamStr(N))
{
char* val = pM->GetParamStr(N);
SetParamStr(FN,val);
}
else
{
double val = pM->GetParam(N);
SetParam(FN,val);
}
CommentParam(FN, pM->GetParamComment(N));
}/* transfer next param */
}/* Transfer params */
void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL)
{
char tmp[1024];
int i;
for(i=0;;++i)
{
char* N = pM->GetParamName(i);
if(N == NULL) break;
if(prefix)
{
strcpy(tmp,prefix);
strcat(tmp,"_");
strcat(tmp,N);
}
else
{
strcpy(tmp,N);
}
if(IsParam(tmp))
{
if(GetParamStr(tmp))
pM->SetParamStr(N,GetParamStr(tmp));
else
pM->SetParam(N,GetParam(tmp));
}
}/* transfer next param */
pM->ParamUpdate();
}/* Transfer params */
virtual void ParamUpdate(){};
char* GetTypeName()
{
return m_pModuleTypeName;
}
int IsModuleTypeName(char* name)
{
return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0;
}
char* GetModuleName()
{
return m_pModuleName;
}
int IsModuleName(char* name)
{
return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0;
}
void SetNickName(char* pStr)
{
if(m_pNickName)
free(m_pNickName);
m_pNickName = NULL;
if(pStr)
m_pNickName = strdup(pStr);
}
char* GetNickName()
{
return m_pNickName ? m_pNickName : (char *)"unknown";
}
virtual void SaveState(CvFileStorage*){};
virtual void LoadState(CvFileStorage*, CvFileNode*){};
virtual void Release() = 0;
};/* CvVMModule */
void inline cvWriteStruct(CvFileStorage* fs, char* name, void* addr, char* desc, int num=1)
{
cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
cvWriteRawData(fs,addr,num,desc);
cvEndWriteStruct(fs);
}
void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, char* name, void* addr, char* desc)
{
CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
if(pSeqNode==NULL)
{
printf("WARNING!!! Can't read structure %s\n",name);
}
else
{
if(CV_NODE_IS_SEQ(pSeqNode->tag))
{
cvReadRawData( fs, pSeqNode, addr, desc );
}
else
{
printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
}
}
}
/* FOREGROUND DETECTOR INTERFACE */
class CV_EXPORTS CvFGDetector: public CvVSModule
{
public:
virtual IplImage* GetMask() = 0;
/* process current image */
virtual void Process(IplImage* pImg) = 0;
/* release foreground detector */
virtual void Release() = 0;
};
inline void cvReleaseFGDetector(CvFGDetector** ppT )
{
ppT[0]->Release();
ppT[0] = 0;
}
/* FOREGROUND DETECTOR INTERFACE */
CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -