X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=cvaux%2Fsrc%2Fvs%2Fblobtrackingmsfgs.cpp;h=a13225e5f4dc5ab1368c0ca847e6b0df58985c6a;hb=80cd7b93506cc1926882d5fd08a2c74ee9359e29;hp=5f560d72a9346361ce4a4b5306907902245b1011;hpb=467a270adf12425827305759c0c4ea8f5b2b3854;p=opencv diff --git a/cvaux/src/vs/blobtrackingmsfgs.cpp b/cvaux/src/vs/blobtrackingmsfgs.cpp index 5f560d7..a13225e 100644 --- a/cvaux/src/vs/blobtrackingmsfgs.cpp +++ b/cvaux/src/vs/blobtrackingmsfgs.cpp @@ -48,24 +48,25 @@ typedef float DefHistType; #define HIST_INDEX(_pData) (((_pData)[0]>>m_ByteShift) + (((_pData)[1]>>(m_ByteShift))<>m_ByteShift)<<(m_BinBit*2))) void calcKernelEpanechnikov(CvMat* pK) -{/* allocate kernel for histogramm creation */ +{ /* Allocate kernel for histogramm creation: */ int x,y; int w = pK->width; int h = pK->height; float x0 = 0.5f*(w-1); float y0 = 0.5f*(h-1); - for(y=0;ywidth; @@ -172,7 +179,7 @@ private: if(m_Dim == 3) { - for(y=0;y=pImg->width) continue; if((x0+x)<0)continue; + if(pMaskData==NULL || pMaskData[x]>128) { DefHistType K = pKernelData[x]; @@ -193,22 +202,28 @@ private: assert(index >= 0 && index < pHist->cols); Volume += K; ((DefHistType*)(pHist->data.ptr))[index] += K; - }/* only masked pixels */ - }/* next column */ - }/* next row */ - }/* if m_Dim == 3 */ + + } /* Only masked pixels. */ + } /* Next column. */ + } /* Next row. */ + } /* if m_Dim == 3. */ + if(pHistVolume)pHistVolume[0] = Volume; - };/*calcHist*/ + + }; /* calcHist */ + double calcBhattacharyya() { cvMul(m_HistCandidate,m_HistModel,m_HistTemp); cvPow(m_HistTemp,m_HistTemp,0.5); return cvSum(m_HistTemp).val[0] / sqrt(m_HistCandidateVolume*m_HistModelVolume); - } /* calcBhattacharyyaCoefficient */ + } /* calcBhattacharyyaCoefficient */ + void calcWeights(IplImage* pImg, IplImage* pImgFG, CvPoint Center) { cvZero(m_Weights); - /* calc new pos */ + + /* Calculate new position: */ if(m_Dim == 3) { int x0 = Center.x - m_KernelMeanShiftSize.width/2; @@ -218,8 +233,8 @@ private: assert(m_Weights->width == m_KernelMeanShiftSize.width); assert(m_Weights->height == m_KernelMeanShiftSize.height); - /*calc shift vector */ - for(y=0;y0) HM = ((DefHistType*)m_HistModel->data.ptr)[index]/m_HistModelVolume; + if(m_HistCandidateVolume>0) HC = ((DefHistType*)m_HistCandidate->data.ptr)[index]/m_HistCandidateVolume; V = (HC>0)?sqrt(HM / HC):0; V += m_FGWeight*(pMaskData?((pMaskData[x]/255.0f)):0); pWData[x] = (float)MIN(V,100000); - }/* next column */ - }/* next row */ - }/* if m_Dim == 3 */ - }/* calcWeights */ + + } /* Next column. */ + } /* Next row. */ + } /* if m_Dim == 3. */ + } /* calcWeights */ public: CvBlobTrackerOneMSFGS() @@ -262,7 +279,7 @@ public: m_FGWeight = 0; m_Alpha = 0.0; - /* add several parameters for external use */ + /* Add several parameters for external use: */ AddParam("FGWeight", &m_FGWeight); CommentParam("FGWeight","Weight of FG mask using (0 - mask will not be used for tracking)"); AddParam("Alpha", &m_Alpha); @@ -276,13 +293,15 @@ public: m_KernelHistModel = NULL; m_KernelHistCandidate = NULL; m_Weights = NULL; - for(i=0;i 0) { dx /= sum; @@ -363,7 +391,7 @@ public: m_Blob.x += dx; m_Blob.y += dy; - { /* mean shift in scale space */ + { /* Mean shift in scale space: */ float news = 0; float sum = 0; float scale; @@ -372,6 +400,7 @@ public: calcHist(pImg, NULL, Center, m_KernelHistCandidate, m_HistCandidate, &m_HistCandidateVolume); calcWeights(pImg, pImgFG, Center); //cvSet(m_Weights,cvScalar(1)); + for(si=0; si0) { news /= sum; } + scale = (float)pow((double)SCALE_BASE,(double)news); m_Blob.w *= scale; m_Blob.h *= scale; - } /* mean shift in scale space */ + } /* Mean shift in scale space. */ - /* check fo finish */ + /* Check fo finish: */ if(fabs(dx)<0.1 && fabs(dy)<0.1) break; - }/* next iteration */ + + } /* Next iteration. */ if(m_Alpha>0) - {/* update hist */ + { /* Update histogram: */ double Vol, WM, WC; CvPoint Center = cvPoint(cvRound(m_Blob.x),cvRound(m_Blob.y)); calcHist(pImg, pImgFG, Center, m_KernelHistModel, m_HistCandidate, &m_HistCandidateVolume); @@ -402,10 +434,12 @@ public: WC = Vol*(m_Alpha)/m_HistCandidateVolume; cvAddWeighted(m_HistModel, WM, m_HistCandidate,WC,0,m_HistModel); m_HistModelVolume = (float)cvSum(m_HistModel).val[0]; - }/* update hist */ + } /* Update histogram. */ return &m_Blob; - }; /* Process */ + + }; /* Process */ + virtual void Release(){delete this;}; }; /*CvBlobTrackerOneMSFGS*/ @@ -413,6 +447,7 @@ CvBlobTrackerOne* cvCreateBlobTrackerOneMSFGS() { return (CvBlobTrackerOne*) new CvBlobTrackerOneMSFGS; } + CvBlobTracker* cvCreateBlobTrackerMSFGS() { return cvCreateBlobTrackerList(cvCreateBlobTrackerOneMSFGS);