⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condens.cpp

📁 微软的基于HMM的人脸识别原代码, 非常经典的说
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    if(IsTracking == false)
    {
        if(IsInit == false)
        {
            CvPoint p1, p2;
            // Draw box
            p1.x = cvRound( size.width * m_params.x );
            p1.y = cvRound( size.height * m_params.y );

            p2.x = cvRound( size.width * (m_params.x + m_params.width));
            p2.y = cvRound( size.height * (m_params.y + m_params.height));

            CheckBackProject( &image );

            cvRectangle( &image, p1, p2, -1, 1 );
        }
        else
        {
            m_object.x = cvRound( size.width * m_params.x );
            m_object.y = cvRound( size.height * m_params.y );
            m_object.width = cvRound( size.width * m_params.width );
            m_object.height = cvRound( size.height * m_params.height );
            ApplyCamShift( &image, true );

            CheckBackProject( &image );

            IsTracking = true;
        }
    }
    else
    {
        cvConDensUpdateByTime(ConDens);
        m_object.x = cvRound( ConDens->State[0]-m_object.width*0.5);
        m_object.y = cvRound( ConDens->State[2]-m_object.height*0.5 );
        
        ApplyCamShift( &image, false );

        CheckBackProject( &image );

        cvRectangle( &image,
                     cvPoint( m_object.x, m_object.y ),
                     cvPoint( m_object.x + m_object.width, m_object.y + m_object.height ),
                     -1, 1 );
        
        Rectang(&image,m_Indicat1,-1);
        m_X.x = 10;
        m_X.y = 10;
        m_X.width=50*m_Old.x/size.width;
        m_X.height =10;
        Rectang(&image,m_X,CV_RGB(0,0,255));
        m_Y.x = 10;
        m_Y.y = 10;
        m_Y.width=10;
        m_Y.height = 50*m_Old.y/size.height;
        Rectang(&image,m_Y,CV_RGB(255,0,0));
        m_Indicat2.x = 0; 
        m_Indicat2.y = size.height-50;
        m_Indicat2.width = 50;
        m_Indicat2.height = 50;
        Rectang(&image,m_Indicat2,-1);
        float Norm = cvSqrt(Measurement[1]*Measurement[1]+Measurement[3]*Measurement[3]);
        int VXNorm = (fabs(Measurement[1])>5)?(int)(12*Measurement[1]/Norm):0;
        int VYNorm = (fabs(Measurement[3])>5)?(int)(12*Measurement[3]/Norm):0;
        CvPoint pp1 = {25,size.height-25};
        CvPoint pp2 = {25+VXNorm,size.height-25+VYNorm};
        cvLine(&image,pp1,pp2,CV_RGB(0,0,0),3);
    }

    cvSetImageData( &image, 0, 0 );
    return NOERROR;
}


//
// CheckInputType
//
// Check the input type is OK, return an error otherwise
//
HRESULT CCondens::CheckInputType(const CMediaType *mtIn)
{
    // Check this is a VIDEOINFO type

    if (*mtIn->FormatType() != FORMAT_VideoInfo)
    {
        
    }
    if ((IsEqualGUID(*mtIn->Type(), MEDIATYPE_Video))
        && (IsEqualGUID(*mtIn->Subtype(), MEDIASUBTYPE_RGB24)))return NOERROR;
    return E_INVALIDARG;


} // CheckInputType



// CheckTransform
//
// To be able to transform the formats must be identical
//

HRESULT CCondens::CheckTransform(const CMediaType *mtIn,const CMediaType *mtOut)
{
    HRESULT hr;
    if (FAILED(hr = CheckInputType(mtIn))) {
	return hr;
    }

    // format must be a VIDEOINFOHEADER
    if (*mtOut->FormatType() != FORMAT_VideoInfo) {
	return E_INVALIDARG;
    }
    
    // formats must be big enough 
    if (mtIn->FormatLength() < sizeof(VIDEOINFOHEADER) ||
	mtOut->FormatLength() < sizeof(VIDEOINFOHEADER))
	return E_INVALIDARG;
    
    VIDEOINFO *pInput = (VIDEOINFO *) mtIn->Format();
    VIDEOINFO *pOutput = (VIDEOINFO *) mtOut->Format();
    if (memcmp(&pInput->bmiHeader,&pOutput->bmiHeader,sizeof(BITMAPINFOHEADER)) == 0) {
	return NOERROR;
    }

    return E_INVALIDARG;
} // CheckTransform


//
// DecideBufferSize
//
// Tell the output pin's allocator what size buffers we
// require. Can only do this when the input is connected
//
HRESULT CCondens::DecideBufferSize(IMemAllocator *pAlloc,ALLOCATOR_PROPERTIES *pProperties)
{
    // Is the input pin connected

    if (m_pInput->IsConnected() == FALSE) {
        return E_UNEXPECTED;
    }

    ASSERT(pAlloc);
    ASSERT(pProperties);
    return NOERROR;

} // DecideBufferSize


//
// GetMediaType
//
// I support one type, namely the type of the input pin
// We must be connected to support the single output type
//
HRESULT CCondens::GetMediaType(int iPosition, CMediaType *pMediaType)
{
    // Is the input pin connected

    if (m_pInput->IsConnected() == FALSE) {
        return E_UNEXPECTED;
    }

    // This should never happen

    if (iPosition < 0) {
        return E_INVALIDARG;
    }

    // Do we have more items to offer

    if (iPosition > 0) {
        return VFW_S_NO_MORE_ITEMS;
    }

    *pMediaType = m_pInput->CurrentMediaType();
    return NOERROR;

} // GetMediaType


STDMETHODIMP CCondens::GetParams( CvCondensParams* params )
{
    if( params )
    {
        *params = m_params;
    }
    return NOERROR;
}


STDMETHODIMP CCondens::SetParams( CvCondensParams* params )
{
    CAutoLock cAutoLock(&m_CCondensLock);
    if( params )
    {
        m_params = *params;
    }
    return NOERROR;
}


STDMETHODIMP CCondens::GetState(bool* State)
{
    *State = IsTracking;    
    return NOERROR;
}


STDMETHODIMP CCondens::StartTracking()
{
    CAutoLock cAutoLock(&m_CCondensLock);
    IsInit = true;
    IsTracking = false;
    return NOERROR;
}

STDMETHODIMP CCondens::StopTracking()
{
    CAutoLock cAutoLock(&m_CCondensLock);
    IsInit = IsTracking = false;
    return NOERROR;
}

CCondens::Rectang(IplImage* img, CvRect Rect, int color)
{
    
    for( int j = 0; j < Rect.height; j++ )
    {
        CvPoint p1={Rect.x,Rect.y+j};
        CvPoint p2={Rect.x+Rect.width,Rect.y+j};
        cvLine(img,p1,p2,color);
    }
        
}
//
// GetPages
//
CCondens::CondProbDens(CvConDensation* CD,  float* Measurement)
{
    float Prob = 1;
    for(int i = 0; i < CD->SamplesNum;i++)
    {
        
        Prob =1;
        Prob*=(float)exp(-XCor*XCor*(Measurement[0] - CD->flSamples[i][0])*(Measurement[0]-CD->flSamples[i][0]));
        Prob*=(float)exp(-VXCor*VXCor*(Measurement[1] - CD->flSamples[i][1])*(Measurement[1]-CD->flSamples[i][1]));
        Prob*=(float)exp(-YCor*YCor*(Measurement[2] - CD->flSamples[i][2])*(Measurement[2]-CD->flSamples[i][2]));
        Prob*=(float)exp(-VYCor*VYCor*(Measurement[3] - CD->flSamples[i][3])*(Measurement[3]-CD->flSamples[i][3]));
        CD->flConfidence[i] = Prob;
    }
}
// This is the sole member of ISpecifyPropertyPages
// Returns the clsid's of the property pages we support
//

STDMETHODIMP CCondens::GetPages(CAUUID *pPages)
{
    pPages->cElems = 1;
    pPages->pElems = (GUID *) CoTaskMemAlloc(sizeof(GUID));
    if (pPages->pElems == NULL) {
        return E_OUTOFMEMORY;
    }
    *(pPages->pElems) = CLSID_CCondensPropertyPage;
    return NOERROR;

} // GetPages

//
// DllRegisterServer
//
// Handle registration of this filter
//
STDAPI DllRegisterServer()
{
    return AMovieDllRegisterServer2( TRUE );

} // DllRegisterServer


//
// DllUnregisterServer
//
STDAPI DllUnregisterServer()
{
   return AMovieDllRegisterServer2( FALSE );

} // DllUnregisterServer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -