本文整理汇总了C++中CvBlobSeq类的典型用法代码示例。如果您正苦于以下问题:C++ CvBlobSeq类的具体用法?C++ CvBlobSeq怎么用?C++ CvBlobSeq使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CvBlobSeq类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cvSize
/* cvDetectNewBlobs
* return 1 and fill blob pNewBlob by blob parameters
* if new blob is detected:
*/
int CvBlobDetectorSimple::DetectNewBlob(IplImage* /*pImg*/, IplImage* pFGMask, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList)
{
int result = 0;
CvSize S = cvSize(pFGMask->width,pFGMask->height);
if(m_pMaskBlobNew == NULL ) m_pMaskBlobNew = cvCreateImage(S,IPL_DEPTH_8U,1);
if(m_pMaskBlobExist == NULL ) m_pMaskBlobExist = cvCreateImage(S,IPL_DEPTH_8U,1);
/* Shift blob list: */
{
int i;
if(m_pBlobLists[0]) delete m_pBlobLists[0];
for(i=1;i<EBD_FRAME_NUM;++i)m_pBlobLists[i-1]=m_pBlobLists[i];
m_pBlobLists[EBD_FRAME_NUM-1] = new CvBlobSeq;
} /* Shift blob list. */
/* Create exist blob mask: */
cvCopy(pFGMask, m_pMaskBlobNew);
/* Create contours and add new blobs to blob list: */
{ /* Create blobs: */
CvBlobSeq Blobs;
CvMemStorage* storage = cvCreateMemStorage();
#if 1
{ /* Glue contours: */
cvFindBlobsByCCClasters(m_pMaskBlobNew, &Blobs, storage );
} /* Glue contours. */
#else
{ /**/
IplImage* pIB = cvCloneImage(m_pMaskBlobNew);
CvSeq* cnts = NULL;
CvSeq* cnt = NULL;
cvThreshold(pIB,pIB,128,255,CV_THRESH_BINARY);
cvFindContours(pIB,storage, &cnts, sizeof(CvContour), CV_RETR_EXTERNAL);
/* Process each contour: */
for(cnt = cnts; cnt; cnt=cnt->h_next)
{
CvBlob NewBlob;
/* Image moments: */
double M00,X,Y,XX,YY;
CvMoments m;
CvRect r = ((CvContour*)cnt)->rect;
CvMat mat;
if(r.height < S.height*0.02 || r.width < S.width*0.02) continue;
cvMoments( cvGetSubRect(m_pMaskBlobNew,&mat,r), &m, 0 );
M00 = cvGetSpatialMoment( &m, 0, 0 );
if(M00 <= 0 ) continue;
X = cvGetSpatialMoment( &m, 1, 0 )/M00;
Y = cvGetSpatialMoment( &m, 0, 1 )/M00;
XX = (cvGetSpatialMoment( &m, 2, 0 )/M00) - X*X;
YY = (cvGetSpatialMoment( &m, 0, 2 )/M00) - Y*Y;
NewBlob = cvBlob(r.x+(float)X,r.y+(float)Y,(float)(4*sqrt(XX)),(float)(4*sqrt(YY)));
Blobs.AddBlob(&NewBlob);
} /* Next contour. */
cvReleaseImage(&pIB);
} /* One contour - one blob. */
#endif
{ /* Delete small and intersected blobs: */
int i;
for(i=Blobs.GetBlobNum(); i>0; i--)
{
CvBlob* pB = Blobs.GetBlob(i-1);
if(pB->h < S.height*0.02 || pB->w < S.width*0.02)
{
Blobs.DelBlob(i-1);
continue;
}
if(pOldBlobList)
{
int j;
for(j=pOldBlobList->GetBlobNum(); j>0; j--)
{
CvBlob* pBOld = pOldBlobList->GetBlob(j-1);
if((fabs(pBOld->x-pB->x) < (CV_BLOB_RX(pBOld)+CV_BLOB_RX(pB))) &&
(fabs(pBOld->y-pB->y) < (CV_BLOB_RY(pBOld)+CV_BLOB_RY(pB))))
{ /* Intersection is present, so delete blob from list: */
Blobs.DelBlob(i-1);
break;
}
} /* Check next old blob. */
} /* if pOldBlobList */
} /* Check next blob. */
//.........这里部分代码省略.........
示例2: SaveAll
void SaveAll()
{
int ObjNum = m_TrackList.GetBlobNum();
int i;
char video_name[1024+1];
char* struct_name = NULL;
CvFileStorage* storage = cvOpenFileStorage(m_pFileName,NULL,CV_STORAGE_WRITE_TEXT);
if(storage==NULL)
{
printf("WARNING!!! Cannot open %s file for trajectory output.", m_pFileName);
}
for(i=0; i<1024 && m_pFileName[i]!='.' && m_pFileName[i]!=0; ++i) video_name[i]=m_pFileName[i];
video_name[i] = 0;
for(;i>0; i--)
{
if(video_name[i-1] == '\\') break;
if(video_name[i-1] == '/') break;
if(video_name[i-1] == ':') break;
}
struct_name = video_name + i;
cvStartWriteStruct(storage, struct_name, CV_NODE_SEQ);
for(i=0; i<ObjNum; ++i)
{
char obj_name[1024];
DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
if(pTrack==NULL) continue;
sprintf(obj_name,"%s_obj%d",struct_name,i);
cvStartWriteStruct(storage, NULL, CV_NODE_MAP);
cvWriteInt(storage, "FrameBegin", pTrack->FrameBegin);
cvWriteString(storage, "VideoObj", obj_name);
cvEndWriteStruct( storage );
pTrack->Saved = 1;
}
cvEndWriteStruct( storage );
for(i=0;i<ObjNum;++i)
{
char obj_name[1024];
DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
CvBlobSeq* pSeq = pTrack->pSeq;
sprintf(obj_name,"%s_obj%d",struct_name,i);
cvStartWriteStruct(storage, obj_name, CV_NODE_MAP);
{ /* Write position: */
int j;
CvPoint2D32f p;
cvStartWriteStruct(storage, "Pos", CV_NODE_SEQ|CV_NODE_FLOW);
for(j=0;j<pSeq->GetBlobNum();++j)
{
CvBlob* pB = pSeq->GetBlob(j);
p.x = pB->x/(m_Size.width-1);
p.y = pB->y/(m_Size.height-1);
cvWriteRawData(storage, &p, 1 ,"ff");
}
cvEndWriteStruct( storage );
}
{ /* Write size: */
int j;
CvPoint2D32f p;
cvStartWriteStruct(storage, "Size", CV_NODE_SEQ|CV_NODE_FLOW);
for(j=0; j<pSeq->GetBlobNum(); ++j)
{
CvBlob* pB = pSeq->GetBlob(j);
p.x = pB->w/(m_Size.width-1);
p.y = pB->h/(m_Size.height-1);
cvWriteRawData(storage, &p, 1 ,"ff");
}
cvEndWriteStruct( storage );
}
cvEndWriteStruct( storage );
}
cvReleaseFileStorage(&storage);
} /* Save All */
示例3: GetConfidence
virtual double GetConfidence(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* pImgFG = NULL)
{
/* Define coefficients in exp by exp(-XT*K)=VT: */
static double _KS = -log(0.1)/pow(0.5,2); /* XT = 1, VT = 0.1 - when size is Larger in 2 times Confidence is smoller in 10 times */
static double _KP = -log(0.1)/pow(m_pImg->width*0.02,2); /* XT = 0.02*ImgWidth, VT = 0.1*/
DefBlobTracker* pBT = (DefBlobTracker*)m_BlobList.GetBlob(BlobIndex);
float dx,dy,dw,dh;
float dp2,ds2;
double W = 1;
CvBlob* pBC = GetNearestBlob(pBlob);
if(pBC == NULL ) return 0;
dx = pBC->x-pBlob->x;
dy = pBC->y-pBlob->y;
dw = (pBC->w-pBlob->w)/pBC->w;
dh = (pBC->h-pBlob->h)/pBC->h;
dp2 = dx*dx+dy*dy;
ds2 = dw*dw+dh*dh;
if(!pBT->Collision)
{ /* Confidence for size by nearest blob: */
W*=exp(-_KS*ds2);
}
if(m_ConfidenceType==0 && !pBT->Collision)
{ /* Confidence by nearest blob: */
W*=exp(-_KP*dp2);
}
if(m_ConfidenceType==1 && pBT->AverFG>0)
{ /* Calculate sum of mask: */
float Aver = CalcAverageMask(pBlob, pImgFG );
if(Aver < pBT->AverFG)
{
float diff = 1+0.9f*(Aver-pBT->AverFG)/pBT->AverFG;
if(diff < 0.1f) diff = 0.1f;
W *= diff;
}
} /* Calculate sum of mask. */
if(m_ConfidenceType==2)
{ /* Calculate BCoeff: */
float S = 0.2f;
float Aver = CalcAverageMask(pBlob, pImgFG );
double B = sqrt(Aver*pBT->AverFG)+sqrt((1-Aver)*(1-pBT->AverFG));
W *= exp((B-1)/(2*S));
} /* Calculate sum of mask. */
return W;
};
示例4: SaveState
virtual void SaveState(CvFileStorage* fs)
{
int b,bN = m_BlobList.GetBlobNum();
cvWriteInt(fs,"BlobNum",m_BlobList.GetBlobNum());
cvStartWriteStruct(fs,"BlobList",CV_NODE_SEQ);
for(b=0; b<bN; ++b)
{
DefBlobTrackerCR* pF = (DefBlobTrackerCR*)m_BlobList.GetBlob(b);
cvStartWriteStruct(fs,NULL,CV_NODE_MAP);
cvWriteInt(fs,"ID",CV_BLOB_ID(pF));
cvStartWriteStruct(fs,"Blob",CV_NODE_SEQ|CV_NODE_FLOW);
cvWriteRawData(fs,&(pF->blob),1,"ffffi");
cvEndWriteStruct(fs);
cvStartWriteStruct(fs,"BlobPredict",CV_NODE_SEQ|CV_NODE_FLOW);
cvWriteRawData(fs,&(pF->BlobPredict),1,"ffffi");
cvEndWriteStruct(fs);
cvStartWriteStruct(fs,"BlobPrev",CV_NODE_SEQ|CV_NODE_FLOW);
cvWriteRawData(fs,&(pF->BlobPrev),1,"ffffi");
cvEndWriteStruct(fs);
pF->pBlobHyp->Write(fs,"BlobHyp");
cvWriteInt(fs,"Collision",pF->Collision);
cvStartWriteStruct(fs,"Predictor",CV_NODE_MAP);
pF->pPredictor->SaveState(fs);
cvEndWriteStruct(fs);
cvStartWriteStruct(fs,"Resolver",CV_NODE_MAP);
pF->pResolver->SaveState(fs);
cvEndWriteStruct(fs);
cvEndWriteStruct(fs);
}
cvEndWriteStruct(fs);
} /* SaveState. */
示例5: ProcessBlob
virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
{/*输入是 已跟踪目标的index 和目标的团块
如果不考虑碰撞, 在新前景团块链表总 找最近的,更新
考虑碰撞: 团块位置= 预测值
*/
//pBlob 是 外界目标Id对应的团块 BlobIndex是他的INdex
//pB是内部cc类 自己的目标团块
//pBT是 内部团块的特殊表示
int ID = pBlob->ID;
CvBlob* pB = m_BlobList.GetBlob(BlobIndex);
DefBlobTrackerColorTracker* pBT = (DefBlobTrackerColorTracker*)pB;
//CvBlob* pBBest = NULL;
//double DistBest = -1;
int BlobID;
if (pB == NULL) return;
BlobID = pB->ID;//看看ID 同不同?
//对于考虑碰撞的,并且团块发生了碰撞 。 团块位置=团块的预测位置
if (m_Collision && pBT->Collision)
{ /* Tracking in collision: */
pB[0] = pBT->BlobPredict;//将预测的值赋值到团块的位置
CV_BLOB_ID(pB) = BlobID;
} /* Tracking in collision. */
else
{ /* Non-collision tracking: */
CvBlob* pBBest = GetNearestBlob(pB);//用PB和新团块比较 ,获得最近的团块
if (pBBest)
{
float w = pBlob->w*(1 - m_AlphaSize) + m_AlphaSize*pBBest->w;
float h = pBlob->h*(1 - m_AlphaSize) + m_AlphaSize*pBBest->h;
float x = pBlob->x*(1 - m_AlphaPos) + m_AlphaPos*pBBest->x;
float y = pBlob->y*(1 - m_AlphaPos) + m_AlphaPos*pBBest->y;
//按比例更新 目标团块的大小和位置
pB->w = w;
pB->h = h;
pB->x = x;
pB->y = y;
CV_BLOB_ID(pB) = BlobID;
}//这种最近邻匹配只能处理没有碰撞的目标跟踪
} /* Non-collision tracking. */
pBlob[0] = pB[0];
pBlob->ID = ID;
};
示例6: LoadState
virtual void LoadState(CvFileStorage* fs, CvFileNode* node)
{
int b,bN = cvReadIntByName(fs,node,"BlobNum",0);
CvFileNode* pBlobListNode = cvGetFileNodeByName(fs,node,"BlobList");
if(!CV_NODE_IS_SEQ(pBlobListNode->tag)) return;
bN = pBlobListNode->data.seq->total;
for(b=0; b<bN; ++b)
{
DefBlobTrackerCR* pF = NULL;
CvBlob Blob;
CvFileNode* pSeqNode = NULL;
CvFileNode* pBlobNode = (CvFileNode*)cvGetSeqElem(pBlobListNode->data.seq,b);
assert(pBlobNode);
Blob.ID = cvReadIntByName(fs,pBlobNode,"ID",0);
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "Blob");
if(CV_NODE_IS_SEQ(pSeqNode->tag))
cvReadRawData( fs, pSeqNode, &Blob, "ffffi" );
AddBlob(&Blob,NULL,NULL);
pF = (DefBlobTrackerCR*)m_BlobList.GetBlobByID(Blob.ID);
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "BlobPredict");
if(CV_NODE_IS_SEQ(pSeqNode->tag))
cvReadRawData( fs, pSeqNode, &pF->BlobPredict, "ffffi" );
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "BlobPrev");
if(CV_NODE_IS_SEQ(pSeqNode->tag))
cvReadRawData( fs, pSeqNode, &pF->BlobPrev, "ffffi" );
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "BlobHyp");
if(pSeqNode)
pF->pBlobHyp->Load(fs,pSeqNode);
pF->Collision = cvReadIntByName(fs, pBlobNode,"Collision",pF->Collision);
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "Predictor");
if(pSeqNode)
pF->pPredictor->LoadState(fs,pSeqNode);
pSeqNode = cvGetFileNodeByName(fs, pBlobNode, "Resolver");
if(pSeqNode)
pF->pResolver->LoadState(fs,pSeqNode);
} /* Read next blob. */
} /* CCwithCR LoadState */
示例7: ProcessBlob
virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
{
int ID = pBlob->ID;
CvBlob* pB = m_BlobList.GetBlob(BlobIndex);
DefBlobTracker* pBT = (DefBlobTracker*)pB;
//CvBlob* pBBest = NULL;
//double DistBest = -1;
int BlobID;
if(pB==NULL) return;
BlobID = pB->ID;
if(m_Collision && pBT->Collision)
{ /* Tracking in collision: */
pB[0]=pBT->BlobPredict;
CV_BLOB_ID(pB)=BlobID;
} /* Tracking in collision. */
else
{ /* Non-collision tracking: */
CvBlob* pBBest = GetNearestBlob(pB);
if(pBBest)
{
float w = pBlob->w*(1-m_AlphaSize)+m_AlphaSize*pBBest->w;
float h = pBlob->h*(1-m_AlphaSize)+m_AlphaSize*pBBest->h;
float x = pBlob->x*(1-m_AlphaPos)+m_AlphaPos*pBBest->x;
float y = pBlob->y*(1-m_AlphaPos)+m_AlphaPos*pBBest->y;
pB->w = w;
pB->h = h;
pB->x = x;
pB->y = y;
CV_BLOB_ID(pB) = BlobID;
}
} /* Non-collision tracking. */
pBlob[0] = pB[0];
pBlob->ID = ID;
};
示例8: SetBlob
virtual void SetBlob(int BlobIndex, CvBlob* pBlob)
{
CvBlob* pB = m_BlobList.GetBlob(BlobIndex);
if(pB) pB[0] = pBlob[0];
};
示例9: GetBlob
virtual CvBlob* GetBlob(int BlobIndex){return m_BlobList.GetBlob(BlobIndex);};
示例10: SaveState
virtual void SaveState(CvFileStorage* fs)
{
cvWriteInt(fs,"FrameCount",m_FrameCount);
cvWriteInt(fs,"NextBlobID",m_NextBlobID);
m_BlobList.Write(fs,"BlobList");
};
示例11: GetBlobHyp
/* Return pointer to specified blob hypothesis by index blob: */
virtual CvBlob* GetBlobHyp(int BlobIndex, int hypothesis)
{
DefBlobTracker* pBT = (DefBlobTracker*)m_BlobList.GetBlob(BlobIndex);
assert(pBT->pBlobHyp);
return pBT->pBlobHyp->GetBlob(hypothesis);
}; /* CvBlobtrackerList::GetBlobHyp() */
示例12: GetBlobNum
int GetBlobNum(){return m_BlobFilterList.GetBlobNum();};
示例13: Process
virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL)
{
CvSeq* cnts;
CvSeq* cnt;
int i;
//CvMat* pMC = NULL;
if(m_BlobList.GetBlobNum() <= 0 ) return;
/* Clear blob list for new blobs: */
m_BlobListNew.Clear();
assert(m_pMem);
cvClearMemStorage(m_pMem);
assert(pImgFG);
{ /* One contour - one blob: */
IplImage* pBin = cvCloneImage(pImgFG);
assert(pBin);
cvThreshold(pBin,pBin,128,255,CV_THRESH_BINARY);
cvFindContours(pBin, m_pMem, &cnts, sizeof(CvContour), CV_RETR_EXTERNAL);
/* Process each contour: */
for(cnt = cnts; cnt; cnt=cnt->h_next)
{
CvBlob NewBlob;
/* Image moments: */
double M00,X,Y,XX,YY;
CvMoments m;
CvRect r = ((CvContour*)cnt)->rect;
CvMat mat;
if(r.height < 3 || r.width < 3) continue;
cvMoments( cvGetSubRect(pImgFG,&mat,r), &m, 0 );
M00 = cvGetSpatialMoment( &m, 0, 0 );
if(M00 <= 0 ) continue;
X = cvGetSpatialMoment( &m, 1, 0 )/M00;
Y = cvGetSpatialMoment( &m, 0, 1 )/M00;
XX = (cvGetSpatialMoment( &m, 2, 0 )/M00) - X*X;
YY = (cvGetSpatialMoment( &m, 0, 2 )/M00) - Y*Y;
NewBlob = cvBlob(r.x+(float)X,r.y+(float)Y,(float)(4*sqrt(XX)),(float)(4*sqrt(YY)));
m_BlobListNew.AddBlob(&NewBlob);
} /* Next contour. */
cvReleaseImage(&pBin);
}
for(i=m_BlobList.GetBlobNum(); i>0; --i)
{ /* Predict new blob position. */
CvBlob* pB = NULL;
DefBlobTrackerCR* pBT = (DefBlobTrackerCR*)m_BlobList.GetBlob(i-1);
/* Update predictor. */
pBT->pPredictor->Update(&(pBT->blob));
pB = pBT->pPredictor->Predict();
if(pB)
{
pBT->BlobPredict = pB[0];
}
pBT->BlobPrev = pBT->blob;
} /* Predict new blob position. */
if(m_BlobList.GetBlobNum()>0 && m_BlobListNew.GetBlobNum()>0)
{ /* Resolve new blob to old: */
int i,j;
int NOld = m_BlobList.GetBlobNum();
int NNew = m_BlobListNew.GetBlobNum();
for(i=0; i<NOld; i++)
{ /* Set 0 collision and clear all hyp: */
DefBlobTrackerCR* pF = (DefBlobTrackerCR*)m_BlobList.GetBlob(i);
pF->Collision = 0;
pF->pBlobHyp->Clear();
} /* Set 0 collision. */
/* Create correspondence records: */
for(j=0; j<NNew; ++j)
{
CvBlob* pB1 = m_BlobListNew.GetBlob(j);
DefBlobTrackerCR* pFLast = NULL;
for(i=0; i<NOld; i++)
{ /* Check intersection: */
int Intersection = 0;
DefBlobTrackerCR* pF = (DefBlobTrackerCR*)m_BlobList.GetBlob(i);
CvBlob* pB2 = &(pF->BlobPredict);
if( fabs(pB1->x-pB2->x)<0.5*(pB1->w+pB2->w) &&
fabs(pB1->y-pB2->y)<0.5*(pB1->h+pB2->h) ) Intersection = 1;
if(Intersection)
{
if(pFLast)
{
pF->Collision = pFLast->Collision = 1;
}
pFLast = pF;
pF->pBlobHyp->AddBlob(pB1);
//.........这里部分代码省略.........
示例14: GetState
float GetState(int BlobID)
{
DefTrackAnalyser* pF = (DefTrackAnalyser*)m_TrackAnalyserList.GetBlobByID(BlobID);
return pF?pF->state:0.f;
};
示例15: GetBlobByID
virtual CvBlob* GetBlobByID(int BlobID){return m_BlobList.GetBlobByID(BlobID);};