📄 blobtrackingauto.cpp
字号:
/* 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 data of tracked blob list */
CvBlob* pB = m_BlobList.GetBlob(i-1);
if(pB && m_pBT->GetBlobByID(CV_BLOB_ID(pB)) == NULL )
{
m_BlobList.DelBlob(i-1);
}
}/* next blob */
}/* update blob list */
TIME_BEGIN()
if(m_pBTPostProc)
{/* post processing module */
int i;
for(i=m_BlobList.GetBlobNum();i>0;--i)
{/* update data of tracked blob list */
CvBlob* pB = m_BlobList.GetBlob(i-1);
m_pBTPostProc->AddBlob(pB);
}
m_pBTPostProc->Process();
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);
CvBlob* pBN = m_pBTPostProc->GetBlobByID(BlobID);
if(pBN && m_UsePPData && pBN->w >= CV_BLOB_MINW && pBN->h >= CV_BLOB_MINH)
{ /* set new data for tracker */
m_pBT->SetBlobByID(BlobID, pBN );
}
if(pBN)
{/* update blob list by result from postprocessing */
pB[0] = pBN[0];
}
}
}/* post processing module */
TIME_END("PostProcessing",CurBlobNum)
/* Blob deleter (experimental and simple)*/
TIME_BEGIN()
if(pFG)
{/* Blob deleter */
int i;
if(!m_BTReal)for(i=m_BlobList.GetBlobNum();i>0;--i)
{/* check all blobs from list */
CvBlobTrackAuto* pB = (CvBlobTrackAuto*)(m_BlobList.GetBlob(i-1));
int Good = 0;
int w=pFG->width;
int h=pFG->height;
CvRect r = CV_BLOB_RECT(pB);
CvMat mat;
double aver = 0;
double area = CV_BLOB_WX(pB)*CV_BLOB_WY(pB);
if(r.x < 0){r.width += r.x;r.x = 0;}
if(r.y < 0){r.height += r.y;r.y = 0;}
if(r.x+r.width>=w){r.width = w-r.x-1;}
if(r.y+r.height>=h){r.height = h-r.y-1;}
if(r.width > 4 && r.height > 4 && r.x < w && r.y < h &&
r.x >=0 && r.y >=0 &&
r.x+r.width < w && r.y+r.height < h && area > 0)
{
aver = cvSum(cvGetSubRect(pFG,&mat,r)).val[0] / area;
/* if mask in blob area exists then its blob OK*/
if(aver > 0.1*255)Good = 1;
}
else
{
pB->BadFrames+=2;
}
if(Good)
{
pB->BadFrames = 0;
}
else
{
pB->BadFrames++;
}
}/* next blob */
/* check error count */
for(i=0;i<m_BlobList.GetBlobNum();++i)
{
CvBlobTrackAuto* pB = (CvBlobTrackAuto*)m_BlobList.GetBlob(i);
if(pB->BadFrames>3)
{/* delete such object */
/* from tracker */
m_pBT->DelBlobByID(CV_BLOB_ID(pB));
/* from local list */
m_BlobList.DelBlob(i);
i--;
}
}/* check error count for next blob */
}/* Blob deleter */
TIME_END("BlobDeleter",m_BlobList.GetBlobNum())
/* Update blobs */
TIME_BEGIN()
if(m_pBT)
m_pBT->Update(pImg, pFG);
TIME_END("BlobTrackerUpdate",CurBlobNum)
/* detect new blob */
TIME_BEGIN()
if(!m_BTReal && m_pBD && pFG && (m_FrameCount > m_FGTrainFrames) )
{/* detect new blob */
static CvBlobSeq NewBlobList;
CvBlobTrackAuto NewB;
NewBlobList.Clear();
if(m_pBD->DetectNewBlob(pImg, pFG, &NewBlobList, &m_BlobList))
{/* add new blob to tracker and blob list */
int i;
IplImage* pMask = pFG;
/*if(0)if(NewBlobList.GetBlobNum()>0 && pFG )
{// erode FG mask (only for FG_0 and MS1||MS2)
pMask = cvCloneImage(pFG);
cvErode(pFG,pMask,NULL,2);
}*/
for(i=0;i<NewBlobList.GetBlobNum();++i)
{
CvBlob* pBN = NewBlobList.GetBlob(i);
pBN->ID = m_NextBlobID;
if(pBN && pBN->w >= CV_BLOB_MINW && pBN->h >= CV_BLOB_MINH)
{
CvBlob* pB = m_pBT->AddBlob(pBN, pImg, pMask );
if(pB)
{
NewB.blob = pB[0];
NewB.BadFrames = 0;
m_BlobList.AddBlob((CvBlob*)&NewB);
m_NextBlobID++;
}
}
}/* add next blob from list of detected blob */
if(pMask != pFG) cvReleaseImage(&pMask);
}/* create and add new blobs and trackers */
}/* detect new blob */
TIME_END("BlobDetector",-1)
TIME_BEGIN()
if(m_pBTGen)
{/* run tracj generator */
for(i=m_BlobList.GetBlobNum();i>0;--i)
{/* update data of tracked blob list */
CvBlob* pB = m_BlobList.GetBlob(i-1);
m_pBTGen->AddBlob(pB);
}
m_pBTGen->Process(pImg, pFG);
}/* run tracj generator */
TIME_END("TrajectoryGeneration",-1)
TIME_BEGIN()
if(m_pBTA)
{/* trajectory analysis module */
int i;
for(i=m_BlobList.GetBlobNum();i>0;i--)
m_pBTA->AddBlob(m_BlobList.GetBlob(i-1));
m_pBTA->Process(pImg, pFG);
}/* trajectory analysis module */
TIME_END("TrackAnalysis",m_BlobList.GetBlobNum())
}/* CvBlobTrackerAuto1::Process */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -