本文整理汇总了C++中CvBlobSeq::GetBlobNum方法的典型用法代码示例。如果您正苦于以下问题:C++ CvBlobSeq::GetBlobNum方法的具体用法?C++ CvBlobSeq::GetBlobNum怎么用?C++ CvBlobSeq::GetBlobNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvBlobSeq
的用法示例。
在下文中一共展示了CvBlobSeq::GetBlobNum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNearestBlob
CvBlob* GetNearestBlob(CvBlob* pB)
{
//DefBlobTracker* pBT = (DefBlobTracker*)pB;
CvBlob* pBBest = NULL;
double DistBest = -1;
if(pB==NULL) return NULL;
for(int j=m_BlobListNew.GetBlobNum(); j>0; --j)
{ /* Find best CC: */
double Dist = -1;
CvBlob* pBNew = m_BlobListNew.GetBlob(j-1);
double dx = fabs(CV_BLOB_X(pB)-CV_BLOB_X(pBNew));
double dy = fabs(CV_BLOB_Y(pB)-CV_BLOB_Y(pBNew));
if(dx > 2*CV_BLOB_WX(pB) || dy > 2*CV_BLOB_WY(pB)) continue;
Dist = sqrt(dx*dx+dy*dy);
if(Dist < DistBest || pBBest == NULL)
{
DistBest = Dist;
pBBest = pBNew;
}
} /* Find best CC. */
return pBBest;
}; /* GetNearestBlob */
示例2: SaveTrack
static void SaveTrack(DefBlobTrack* pTrack, char* pFileName, int norm = 0)
{ /* Save blob track: */
int j;
FILE* out = NULL;
CvBlobSeq* pS = pTrack->pSeq;
CvBlob* pB0 = pS?pS->GetBlob(0):NULL;
if(pFileName == NULL) return;
if(pTrack == NULL) return;
out = fopen(pFileName,"at");
if(out == NULL)
{
printf("Warning! Cannot open %s file for track output\n", pFileName);
return;
}
fprintf(out,"%d",pTrack->FrameBegin);
if(pS) for(j=0; j<pS->GetBlobNum(); ++j)
{
CvBlob* pB = pS->GetBlob(j);
fprintf(out,", %.1f, %.1f", CV_BLOB_X(pB),CV_BLOB_Y(pB));
if(CV_BLOB_WX(pB0)>0)
fprintf(out,", %.2f",CV_BLOB_WX(pB)/(norm?CV_BLOB_WX(pB0):1));
if(CV_BLOB_WY(pB0)>0)
fprintf(out,", %.2f",CV_BLOB_WY(pB)/(norm?CV_BLOB_WY(pB0):1));
}
fprintf(out,"\n");
fclose(out);
pTrack->Saved = 1;
} /* Save blob track. */
示例3:
~CvBlobTrackAnalysisList()
{
int i;
for(i=m_TrackAnalyserList.GetBlobNum(); i>0; --i)
{
DefTrackAnalyser* pF = (DefTrackAnalyser*)m_TrackAnalyserList.GetBlob(i-1);
pF->pFilter->Release();
}
};
示例4:
~CvBlobTrackAnalysisTrackDist() {
int i;
for (i = m_Tracks.GetBlobNum(); i > 0; --i) {
DefTrackForDist* pF = (DefTrackForDist*)m_Tracks.GetBlob(i - 1);
delete pF->pTrack;
}
if (m_pDebugImg) { cvReleaseImage(&m_pDebugImg); }
//if(m_pDebugAVI) cvReleaseVideoWriter(&m_pDebugAVI);
} /* Destructor. */
示例5:
~CvBlobTrackPostProcList()
{
int i;
for(i=m_BlobFilterList.GetBlobNum();i>0;--i)
{
DefBlobFilter* pF = (DefBlobFilter*)m_BlobFilterList.GetBlob(i-1);
pF->pFilter->Release();
}
};
示例6: SaveAll
~CvBlobTrackGenYML() {
int i;
SaveAll();
for (i = m_TrackList.GetBlobNum(); i > 0; --i) {
DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i - 1);
/* Delete sequence: */
delete pTrack->pSeq;
pTrack->pSeq = NULL;
} /* Check next track. */
} /* Destructor. */
示例7: AddBlob
/* return pointer to new added blob */
virtual CvBlob* AddBlob(CvBlob* pB, IplImage* /*pImg*/, IplImage* pImgFG = NULL )
{
assert(pImgFG); /* This tracker uses only foreground mask. */
DefBlobTracker NewB;
NewB.blob = pB[0];
// CV_BLOB_ID(&NewB) = m_LastID;
NewB.pBlobHyp = new CvBlobSeq;
NewB.pPredictor = cvCreateModuleBlobTrackPredictKalman(); /* Module for position prediction. */
NewB.pPredictor->Update(pB);
NewB.AverFG = pImgFG?CalcAverageMask(pB,pImgFG):0;
m_BlobList.AddBlob((CvBlob*)&NewB);
return m_BlobList.GetBlob(m_BlobList.GetBlobNum()-1);
};
示例8: 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. */
示例9: Process
void Process(IplImage* pImg = NULL, IplImage* /*pFG*/ = NULL) {
int i;
m_Size = cvSize(pImg->width, pImg->height);
for (i = m_TrackList.GetBlobNum(); i > 0; --i) {
DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i - 1);
if (pTrack->FrameLast < m_Frame && !pTrack->Saved) {
/* Save track: */
SaveAll();
} /* Save track. */
} /* Check next track. */
m_Frame++;
}
示例10: AddBlob
/* Return pointer to new added blob: */
virtual CvBlob* AddBlob(CvBlob* pB, IplImage* pImg, IplImage* pImgFG = NULL )
{
DefBlobTrackerCR NewB;
NewB.blob = pB[0];
NewB.pBlobHyp = new CvBlobSeq;
NewB.pPredictor = cvCreateModuleBlobTrackPredictKalman(); /* module for predict position */
NewB.pPredictor->SetParam("DataNoisePos",0.001);
NewB.pPredictor->ParamUpdate();
NewB.pResolver = NULL;
if(m_CreateCR)
{
NewB.pResolver = m_CreateCR();
TransferParamsToChild(NewB.pResolver,NULL);
NewB.pResolver->Init(pB, pImg, pImgFG);
}
m_BlobList.AddBlob((CvBlob*)&NewB);
return m_BlobList.GetBlob(m_BlobList.GetBlobNum()-1);
};
示例11: SetBlobHyp
/* Set new parameters for specified (by index) blob hypothesis
* (can be called several times for each hypothesis):
*/
virtual void SetBlobHyp(int BlobIndex, CvBlob* pBlob)
{
if(m_ClearHyp)
{ /* Clear all hypotheses: */
int b, bN = m_BlobList.GetBlobNum();
for(b=0; b<bN; ++b)
{
DefBlobTracker* pBT = (DefBlobTracker*)m_BlobList.GetBlob(b);
assert(pBT->pBlobHyp);
pBT->pBlobHyp->Clear();
}
m_ClearHyp = 0;
}
{ /* Add hypothesis: */
DefBlobTracker* pBT = (DefBlobTracker*)m_BlobList.GetBlob(BlobIndex);
assert(pBT->pBlobHyp);
pBT->pBlobHyp->AddBlob(pBlob);
}
};
示例12: Process
virtual void Process(IplImage* pImg, IplImage* pFG)
{
int i;
for(i=m_TrackAnalyserList.GetBlobNum(); i>0; --i)
{
DefTrackAnalyser* pF = (DefTrackAnalyser*)m_TrackAnalyserList.GetBlob(i-1);
if(pF->m_LastFrame == m_Frame)
{ /* Process: */
int ID = CV_BLOB_ID(pF);
pF->state = pF->pFilter->Process(&(pF->blob), pImg, pFG);
CV_BLOB_ID(pF) = ID;
}
else
{ /* Delete blob filter: */
pF->pFilter->Release();
m_TrackAnalyserList.DelBlob(i-1);
}
} /* Next blob. */
m_Frame++;
};
示例13: Process
virtual void Process()
{
int i;
for(i=m_BlobFilterList.GetBlobNum(); i>0; --i)
{
DefBlobFilter* pF = (DefBlobFilter*)m_BlobFilterList.GetBlob(i-1);
if(pF->m_LastFrame == m_Frame)
{ /* Process: */
int ID = CV_BLOB_ID(pF);
pF->blob = *(pF->pFilter->Process(&(pF->blob)));
CV_BLOB_ID(pF) = ID;
}
else
{ /* Delete blob filter: */
pF->pFilter->Release();
m_BlobFilterList.DelBlob(i-1);
}
} /* Next blob. */
m_Frame++;
};
示例14: cvGetTickCount
void CvBlobTrackerAuto1::Process(IplImage* pImg, IplImage* pMask)
{
int CurBlobNum = 0;
int i;
IplImage* pFG = pMask;
/* Bump frame counter: */
m_FrameCount++;
if(m_TimesFile)
{
static int64 TickCount = cvGetTickCount();
static double TimeSum = 0;
static int Count = 0;
Count++;
if(Count%100==0)
{
#ifndef WINCE
time_t ltime;
time( <ime );
char* stime = ctime( <ime );
#else
/* WINCE does not have above POSIX functions (time,ctime) */
const char* stime = " wince ";
#endif
FILE* out = fopen(m_TimesFile,"at");
double Time;
TickCount = cvGetTickCount()-TickCount;
Time = TickCount/FREQ;
if(out){fprintf(out,"- %sFrame: %d ALL_TIME - %f\n",stime,Count,Time/1000);fclose(out);}
TimeSum = 0;
TickCount = cvGetTickCount();
}
}
/* Update BG model: */
TIME_BEGIN()
if(m_pFG)
{ /* If FG detector is needed: */
m_pFG->Process(pImg);
pFG = m_pFG->GetMask();
} /* If FG detector is needed. */
TIME_END("FGDetector",-1)
m_pFGMask = pFG; /* For external use. */
/*if(m_pFG && m_pFG->GetParam("DebugWnd") == 1)
{// debug foreground result
IplImage *pFG = m_pFG->GetMask();
if(pFG)
{
cvNamedWindow("FG",0);
cvShowImage("FG", pFG);
}
}*/
/* Track blobs: */
TIME_BEGIN()
if(m_pBT)
{
int i;
m_pBT->Process(pImg, pFG);
for(i=m_BlobList.GetBlobNum(); i>0; --i)
{ /* Update data of tracked blob list: */
CvBlob* pB = m_BlobList.GetBlob(i-1);
int BlobID = CV_BLOB_ID(pB);
int i = m_pBT->GetBlobIndexByID(BlobID);
m_pBT->ProcessBlob(i, pB, pImg, pFG);
pB->ID = BlobID;
}
CurBlobNum = m_pBT->GetBlobNum();
}
TIME_END("BlobTracker",CurBlobNum)
/* This part should be removed: */
if(m_BTReal && m_pBT)
{ /* Update blob list (detect new blob for real blob tracker): */
int i;
for(i=m_pBT->GetBlobNum(); i>0; --i)
{ /* Update data of tracked blob list: */
CvBlob* pB = m_pBT->GetBlob(i-1);
if(pB && m_BlobList.GetBlobByID(CV_BLOB_ID(pB)) == NULL )
{
CvBlobTrackAuto NewB;
NewB.blob = pB[0];
NewB.BadFrames = 0;
m_BlobList.AddBlob((CvBlob*)&NewB);
}
} /* Next blob. */
/* Delete blobs: */
for(i=m_BlobList.GetBlobNum(); i>0; --i)
{ /* Update tracked-blob list: */
CvBlob* pB = m_BlobList.GetBlob(i-1);
//.........这里部分代码省略.........
示例15: 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);
//.........这里部分代码省略.........