Exemplo n.º 1
0
void Candidate::GetScoreMaxCCMinBorder( const PointCloud& pc, float bitmapEpsilon, bool doFiltering )
{
	float borderRatio;
	size_t connectedSize = m_shape->ConnectedComponent(pc, bitmapEpsilon, 
					m_indices, doFiltering, &borderRatio);
	m_indices->resize(connectedSize);

	m_score = connectedSize * size_t(( 1.0f - borderRatio ) * ( 1.0f - GetVariance( pc )));
}
Exemplo n.º 2
0
//input box ::符合in5out4規則保留下來的點
static void   MaskEvaluate(int x,int y,int d,unsigned char* src_buf,int buf_width, int buf_height,double* MeanIn,double* MeanOut,double* VarIn,double* VarOut)
{
		int i,j,InNum=0, OutNum=0, AveIn[NumOfInter], AveOut[NumOfOuter];
		//Inter 5
		for(i = y-d;i<=y+d;i=i+d)
		{
		 if(i>=0&&i<buf_height&&x>=0&&x<buf_width)
		 {
		  AveIn[InNum]=  (int)src_buf[x*2+i*buf_width*2];
		  InNum++;
		 }
		}
		if((x-d)>=0&&(x-d)<buf_width)
		{
			AveIn[InNum]=  (int)src_buf[(x-d)*2+y*buf_width*2];//左內
			InNum++;
		}
		if((x+d)>=0&&(x+d)<buf_width)
		{
			AveIn[InNum]=  (int)src_buf[(x+d)*2+y*buf_width*2];//右內
			InNum++;
		}

		//Outer 4
		for( i = x-d;i<=x+d;i+=d*2)
		{
		 for(j = y-d;j<=y+d;j+=d*2)
		 {
		  if(i>=0&&i<buf_width&&j>=0&&j<buf_height)
		  { 
		   AveOut[OutNum]=  (int)src_buf[i*2+j*buf_width*2];
		   OutNum++;
		  }
		 }
		}
		//-------算平均值&變異數--------
		if(InNum!=FALSE&&OutNum!=FALSE)
		{
			*MeanIn  = GetAverage(AveIn,InNum);
			*MeanOut = GetAverage(AveOut,OutNum);
			*VarIn   = GetVariance(AveIn,InNum);
			*VarOut  = GetVariance(AveOut,OutNum);
		}
}
float VarianceAccumulator<T>::GetNStdDev(T value)
{
    T variance = GetVariance();
    T mean = GetMean();
    if (variance > 0) {
        return std::fabs(value - mean) / (std::sqrt(variance));
    } else {
        return 0;
    }
}
void CMyHistorgram::DrawLine(vector<CPoint> pointList, int lineStyle, int lineWidth, COLOR color)
{
	CPen newPen;
	newPen.CreatePen(lineStyle, lineWidth, color);
	m_pDC->SelectObject(&newPen);
	CPoint point;
	int mode;
	if (pointList.size())
	{
		point.x = (pointList[0].x - xMinValue) / xUnit;
		point.y = m_rect.bottom - (pointList[0].y - yMinValue) / yUnit;
		m_pDC->MoveTo(point);

		mode = pointList[0].y;
		m_modeIndex = pointList[0].x;
	}
	for (int i = 1; i < pointList.size(); i++)
	{
		point.x = (pointList[i].x - xMinValue) / xUnit;
		point.y = m_rect.bottom - (pointList[i].y - yMinValue) / yUnit;
		m_pDC->LineTo(point);

		if (pointList[i].y>mode)
		{
			mode = pointList[i].y;
			m_modeIndex = pointList[i].x;
		}
	}
	if (m_bShowEXDX)
	{
		if (pointList.size())
		{
			//m_pDC->MoveTo((m_modeIndex - xMinValue) / xUnit, m_rect.bottom);
			//m_pDC->LineTo((m_modeIndex - xMinValue) / xUnit, m_rect.top);

			m_meanValue = GetMeanValue(pointList);
			m_variance = GetVariance(pointList, m_meanValue);

			CFont font;
			font.CreatePointFont(160, _T("宋体"));
			CFont*def_font = m_pDC->SelectObject(&font);  //选择该字体进入PDC

			CString tempStr;
			tempStr.Format(_T("EX = %.2f"), m_meanValue);
			m_pDC->TextOut(m_rect.left + 40, m_rect.top + 20, tempStr);
			tempStr.Format(_T("DX = %.2f"), m_variance);
			m_pDC->TextOut(m_rect.left + 40, m_rect.top + 60, tempStr);

			m_pDC->SelectObject(def_font);//恢复PDC的缺省字体
			font.DeleteObject();//释放font对象
		}
	}

	
}
Exemplo n.º 5
0
void moTrackerSystemData::DrawFeatures( int w, int h, float offsetx, float offsety ) {

    if (GetFeaturesCount()>0) {

            glEnable( GL_TEXTURE_2D );
            glEnable( GL_BLEND );
            glBlendFunc (GL_SRC_ALPHA, GL_ONE);


            for (int f = 0; f < GetFeaturesCount(); f++)
            {

                moTrackerFeature* pF = GetFeature(f);

                ///solo dibujamos los que son validos...
                if (pF && pF->valid) {

                float x = (pF->x) - offsetx;
                float y = (pF->y) - offsety;
                float tr_x = (pF->tr_x) - offsetx;
                float tr_y = (pF->tr_y) - offsety;
                float v_x = (pF->v_x);
                float v_y = (pF->v_y);
                float vel = sqrtf( v_x*v_x+v_y*v_y );
                int v = pF->val;
                int is_parent = pF->is_parent;

                //MODebug2->Log(moText("    x:")+FloatToStr(pF->x) + moText(" y:")+FloatToStr(pF->y) );

                glBindTexture(GL_TEXTURE_2D,0);
                glColor4f(1.0, 0.0, 0.0, 0.15);

                if (v >= MO_TRACKER_TRACKED) glColor4f(0.0, 1.0, 0.0, 1.0);
                else if (v == MO_TRACKER_NOT_FOUND) glColor4f(1.0, 0.0, 1.0, 1.0);
                else if (v == MO_TRACKER_SMALL_DET) glColor4f(1.0, 0.0, 1.0, 1.0);
                else if (v == MO_TRACKER_MAX_ITERATIONS) glColor4f(1.0, 0.0, 1.0, 1.0);
                else if (v == MO_TRACKER_OOB) glColor4f(1.0, 0.0, 1.0, 1.0);
                else if (v == MO_TRACKER_LARGE_RESIDUE) glColor4f(1.0, 0.0, 1.0, 1.0);

                if ( pF->valid ) {
                    glBegin(GL_QUADS);
                        glVertex2f((tr_x - 0.008)*w, (tr_y - 0.008)*h);
                        glVertex2f((tr_x - 0.008)*w, (tr_y + 0.008)*h);
                        glVertex2f((tr_x + 0.008)*w, (tr_y + 0.008)*h);
                        glVertex2f((tr_x + 0.008)*w, (tr_y - 0.008)*h);
                    glEnd();

                    glBegin(GL_QUADS);
                        glVertex2f((x - 0.008)*w, (y - 0.008)*h);
                        glVertex2f((x - 0.008)*w, (y + 0.008)*h);
                        glVertex2f((x + 0.008)*w, (y + 0.008)*h);
                        glVertex2f((x + 0.008)*w, (y - 0.008)*h);
                    glEnd();

    /*
                    glDisable(GL_TEXTURE_2D);
                    glColor4f(1.0, 1.0, 1.0, 1.0);
                    glBegin(GL_LINES);
                        glVertex2f( x*w, y*h);
                        glVertex2f( tr_x*w, tr_y*h);
                    glEnd();
                    */

                    /*if ( vel > 0.001 ) {
                        glDisable(GL_TEXTURE_2D);
                        glColor4f(0.0, 0.0, 1.0, 1.0);
                        //glPointSize((GLfloat)10);
                        glLineWidth((GLfloat)10.0);
                        glBegin(GL_LINES);
                            glVertex2f( x*w, y*h);
                            glVertex2f( x*w+v_x*w, y*h+v_y*h);
                        glEnd();
                    }*/


                }


            }


    /***********************************************************************************
    **          UPLAS - JUNTANDO VECINOS
    ***********************************************************************************/
/*
            float p1x,p1y;
            float p2x,p2y;
            int k1, k2;
            int Uplas[GetFeaturesCount()];
            ///Reconocer los que tienen un par, de los que tienen 2
            for( int g = 0; g < nPares; g++ ) {
                k1 = m_Pares[g][0];
                k2 = m_Pares[g][1];
                Uplas[k1]++;
                Uplas[k2]++;

                p1x = GetFeature(k1)->x - offsetx;
                p1y = GetFeature(k1)->y - offsety;

                p2x = GetFeature(k2)->x - offsetx;
                p2y = GetFeature(k2)->y - offsety;


                glColor4f(1.0, 1.0, 1.0, 0.1);
                glDisable(GL_TEXTURE_2D);
                glLineWidth((GLfloat)1.0);
                glBegin(GL_LINES);
                    glVertex2f( p1x*w, p1y*h);
                    glVertex2f( p2x*w, p2y*h);
                glEnd();

            }

            int myuplas[3];
            for( int u=0; u<GetFeaturesCount(); u++) {
                if( Uplas[u]>=2) {

                    p1x = GetFeature(u)->x - offsetx;
                    p1y = GetFeature(u)->y - offsety;

                    ///DrawUpla(u);
                    ///search for all points!
                    if (Uplas[u]==3) {
                        int o = 0;
                        moVector2f aver(p1x,p1y);
                        for( int pp=0; pp<nPares; pp++) {
                            k1 = m_Pares[pp][0];
                            k2 = m_Pares[pp][1];
                            if (k1==u) myuplas[o++] = k2;
                            if (k2==u) myuplas[o++] = k1;
                        }
                        for(int pp=0;pp<3;pp++) {
                            aver+= moVector2f( GetFeature(myuplas[pp])->x - offsetx,
                                            GetFeature(myuplas[pp])->y - offsety );
                        }
                        aver/=4;
                        moVector2f aver2;
                        for(int pp=0;pp<3;pp++) {
                            aver2 = aver - moVector2f( GetFeature(myuplas[pp])->x - offsetx,
                                            GetFeature(myuplas[pp])->y - offsety );
                        }

                        glColor4f(1.0, 1.0, 0.0, 0.1);
                        glBegin(GL_QUADS);
                            glVertex2f((aver.X() - 0.02)*w, (aver.Y() - 0.02)*h);
                            glVertex2f((aver.X() - 0.02)*w, (aver.Y() + 0.02)*h);
                            glVertex2f((aver.X() + 0.02)*w, (aver.Y()+ 0.02)*h);
                            glVertex2f((aver.X() + 0.02)*w, (aver.Y() - 0.02)*h);
                        glEnd();
                    }
              }
            }

*/
    /***********************************************************************************
    **          VARIANCE - BARYCENTER - ETC
    ***********************************************************************************/


            moVector2f m_TrackerBarycenter = moVector2f(    GetBarycenter().X() - offsetx,
                                                            GetBarycenter().Y() - offsety );
            moVector2f m_TrackerMin = moVector2f(   GetMin().X() - offsetx,
                                                    GetMin().Y() - offsety );
            moVector2f m_TrackerMax = moVector2f(   GetMax().X() - offsetx,
                                                    GetMax().Y() - offsety );


            glBindTexture(GL_TEXTURE_2D,0);
            glColor4f(0.7, 1.0, 0.5, 0.05);

            //GL_MAX_TEXTURE_UNITS_ARB
            //GL_TEXTURE0_ARB

            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

            glBegin(GL_QUADS);
            glColor4f(0.7, 1.0, 0.5, 0.2);
                glVertex2f((m_TrackerBarycenter.X() - 0.02)*w, (m_TrackerBarycenter.Y() - 0.02)*h);
                glColor4f(0.7, 1.0, 0.5, 0.2);
                glVertex2f((m_TrackerBarycenter.X() - 0.02)*w, (m_TrackerBarycenter.Y() + 0.02)*h);
                glColor4f(0.7, 1.0, 0.5, 0.2);
                glVertex2f((m_TrackerBarycenter.X() + 0.02)*w, (m_TrackerBarycenter.Y() + 0.02)*h);
                glColor4f(0.7, 1.0, 0.5, 0.2);
                glVertex2f((m_TrackerBarycenter.X() + 0.02)*w, (m_TrackerBarycenter.Y() - 0.02)*h);
            glEnd();

            moVector2f m_TrackerVariance = moVector2f(  GetVariance().X(),
                                                        GetVariance().Y());

            ///Max min
            glLineWidth((GLfloat)1.0);
            glBegin(GL_QUADS);
            glColor4f(0.7, 1.0, 0.5, 0.05);
                glVertex2f( m_TrackerMin.X()*w, m_TrackerMax.Y()*h);
                glVertex2f( m_TrackerMax.X()*w, m_TrackerMax.Y()*h);
                glVertex2f( m_TrackerMax.X()*w, m_TrackerMin.Y()*h);
                glVertex2f( m_TrackerMin.X()*w, m_TrackerMin.Y()*h);
            glEnd();

            ///Variance
            glLineWidth((GLfloat)1.5);
            glBegin(GL_QUADS);
                glVertex2f( m_TrackerBarycenter.X()*w - m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h-m_TrackerVariance.Y()*h*5);
                glVertex2f( m_TrackerBarycenter.X()*w + m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h-m_TrackerVariance.Y()*h*5);
                glVertex2f( m_TrackerBarycenter.X()*w + m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h+m_TrackerVariance.Y()*h*5);
                glVertex2f( m_TrackerBarycenter.X()*w - m_TrackerVariance.X()*w*5, m_TrackerBarycenter.Y()*h+m_TrackerVariance.Y()*h*5);
            glEnd();


            //MODebug2->Push(moText("varianza: vx:")+FloatToStr(m_TrackerVariance.X()*w*10)+moText(" vy")+FloatToStr(m_TrackerVariance.Y()*h*10));


    /***********************************************************************************
    **          ZONES
    ***********************************************************************************/
/*
            moText matrix;
            int npz,nmz;
            int n = GetValidFeatures();
            int z;
            float off_w, off_h, off_w_m, off_h_m;
            off_w = off_h = 1.0 / 8.0;

            if ( m_ZoneW > 0 ) {
              off_w = 1.0 / ( (float)(m_ZoneW)*2.0 );
            }
            if ( m_ZoneH > 0 ) {
              off_h = 1.0 / ( float(m_ZoneH)*2.0 );
            }
            off_w_m = off_w - off_w/8.0;
            off_h_m = off_h - off_h/8.0;

            for(z=0; z<m_Zones; z++) {

                    moVector2f poscuad = ZoneToPosition(z);

                    npz = GetPositionMatrix( poscuad );
                    nmz = GetMotionMatrix( poscuad );

                    //matrix = matrix + moText(" ")+IntToStr(npz);
                    poscuad = moVector2f( poscuad.X()-offsetx, poscuad.Y()-offsety);
                    if ( npz > 0 ) {
                            glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
                            //glColor4f( 0.5+0.5*(float)z/(m_Zones-1), 0.5+0.5*(float)z/(m_Zones-1), 0.0, 0.25);
                            glColor4f(0.5, 0.5, 0.0, 0.02);
                            glBegin(GL_QUADS);
                                glVertex2f((poscuad.X() - off_w)*w, (poscuad.Y() - off_h)*h);
                                glVertex2f((poscuad.X() - off_w)*w, (poscuad.Y() + off_h)*h);
                                glVertex2f((poscuad.X() + off_w)*w, (poscuad.Y() + off_h)*h);
                                glVertex2f((poscuad.X() + off_w)*w, (poscuad.Y() - off_h)*h);
                            glEnd();
                    }
                    if ( nmz > 0 ) {

                            ///DRAW ZONE WITH FEATURES IN MOTION

                            glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
                            //glColor4f( 0.0, 0.0, 0.5+0.5*(float)z/(m_Zones-1), 0.25);
                            glColor4f(0.0, 0.0, 0.5, 0.02);
                            glBegin(GL_QUADS);
                                glVertex2f((poscuad.X() - off_w_m)*w, (poscuad.Y() - off_h_m)*h);
                                glVertex2f((poscuad.X() - off_w_m)*w, (poscuad.Y() + off_h_m)*h);
                                glVertex2f((poscuad.X() + off_w_m)*w, (poscuad.Y() + off_h_m)*h);
                                glVertex2f((poscuad.X() + off_w_m)*w, (poscuad.Y() - off_h_m)*h);
                            glEnd();

                    }
            }


            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

            for(int cc=0; cc < m_Zones; cc++) {

                    moVector2f poscuadC = ZoneToPositionC(cc);
                    moVector2f p2,p3,p4;
                    if (((cc+1)%m_ZoneW)==0) { p2 = ZoneToPositionC( cc - m_ZoneW -1); }
                    else { p2 = ZoneToPositionC( cc + 1 ); }

                    if (cc<12) {
                        p3 = GetBarycenter();
                        p4 = GetBarycenter();
                    }
                    else {
                        if (((cc+1)%m_ZoneW)==0) { p3 = ZoneToPositionC( cc - m_ZoneW -1 - m_ZoneW); }
                        else { p3 = ZoneToPositionC( cc + 1 - m_ZoneW); }
                        p4 = ZoneToPositionC( cc - m_ZoneW );

                    }

                    npz = GetPositionMatrixC( cc );
                    nmz = GetMotionMatrixC( cc );

                    //matrix = matrix + moText(" ")+IntToStr(npz);
                    poscuadC = moVector2f( poscuadC.X()-offsetx, poscuadC.Y()-offsety);
                    p2 = moVector2f( p2.X()-offsetx, p2.Y()-offsety );
                    p3 = moVector2f( p3.X()-offsetx, p3.Y()-offsety );
                    p4 = moVector2f( p4.X()-offsetx, p4.Y()-offsety );
                   if ( npz == 0 ) {
                            glColor4f( 0.3+0.2*(float)cc/(m_Zones-1), 0.3+0.2*(float)cc/(m_Zones-1), 0.2, 0.015);
                            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
                   } else {
                       glColor4f( 0.0, 0.7+0.3*(float)cc/(m_Zones-1), 0.0, 0.075);
                       glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

                    }


                            //moVector2f p3 = m_pTrackerData->ZoneToPositionC( cc + 1 + 12 );
                            //moVector2f p4 = m_pTrackerData->ZoneToPositionC( cc + 12 );

                            glBegin(GL_QUADS);
                                glVertex2f( poscuadC.X()*w, poscuadC.Y()*h);
                                glVertex2f( p2.X()*w, p2.Y()*h);
                                glVertex2f( p3.X()*w, p3.Y()*h);
                                glVertex2f( p4.X()*w, p4.Y()*h);
                                //glVertex2f( p3.X()*w, p3.Y()*h);
                                //glVertex2f( p4.X()*w, p4.Y()*h);
                            glEnd();

                   //}
                    if ( nmz > 0 ) {
                            glColor4f( 0.0, 0.0, 0.5+0.5*(float)cc/(m_Zones-1), 0.025);

                    }
            }

            //MODebug2->Push(moText("N:")+(moText)IntToStr(m_pTrackerData->GetValidFeatures())+moText("matrix: vx:")+(moText)matrix);
            */
        }

    }

}