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

📄 cvcam.cpp

📁 是一个人脸识别特征提取的Vc代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            {
                return -1;
            }
        
            int rndheight = cvcam_properties[indexes[0]].rndheight?
            cvcam_properties[indexes[0]].rndheight:
            vih->bmiHeader.biHeight;


            int rndwidth = cvcam_properties[indexes[0]].rndwidth?
            cvcam_properties[indexes[0]].rndwidth:
            vih->bmiHeader.biWidth;
            

            _cvcamVideoWindow->SetWindowPosition( 0, 0, rndwidth, rndheight );
            const char* name = cvGetWindowName(hWnd);
            cvResizeWindow(name, rndwidth, rndheight);

            //renderer->Release();
            //pPin->Release();
            //_cvcamVideoWindow = pVideoWindow;
            
            //pVideoWindow->Release();



        }//if(cvcam_properties[indexes[0]].render)


        if(cvcam_properties[indexes[1]].render)
        {
            output2->ConnectedTo(&pPin);
            pPin->QueryPinInfo(&PinInfo);
            
            renderer = PinInfo.pFilter;

            _objects.push_back(SafeUnknown(pPin));
            _objects.push_back(SafeUnknown(renderer));


            IVideoWindow* pVideoWindow;
            renderer->QueryInterface(IID_IVideoWindow, (void**)&pVideoWindow);

            HWND hWnd;
        
            cvcamGetProperty(indexes[1], CVCAM_PROP_WINDOW, &hWnd);
            if(!hWnd)
            {
                hWnd = _cvcamCreateWindow();
                cvcamSetProperty(indexes[1], CVCAM_PROP_WINDOW, &hWnd);
            }
            
            pVideoWindow->put_Owner((OAHWND)hWnd);

            long flags;
            pVideoWindow->get_WindowStyle(&flags);
            pVideoWindow->put_WindowStyle(flags & (~WS_CAPTION) | WS_CHILD);
            pVideoWindow->put_MessageDrain((OAHWND)hWnd);

            // Get the rectangle dimensions and resize the client window
            AM_MEDIA_TYPE amt;
            pPin->ConnectionMediaType(&amt);
            VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)amt.pbFormat;
            if(!vih)
            {
                return -1;
            }
        
            int rndheight = cvcam_properties[indexes[1]].rndheight?
            cvcam_properties[indexes[1]].rndheight:
            vih->bmiHeader.biHeight;


            int rndwidth = cvcam_properties[indexes[1]].rndwidth?
            cvcam_properties[indexes[1]].rndwidth:
            vih->bmiHeader.biWidth;
            

            pVideoWindow->SetWindowPosition( 0, 0, rndwidth, rndheight );
            const char* name = cvGetWindowName(hWnd);
            cvResizeWindow(name, rndwidth, rndheight);

            
            //renderer->Release();
            //pPin->Release();

            _cvcamVideoWindow2 = pVideoWindow;
            //pVideoWindow->Release();



        }//if(cvcam_properties[indexes[0]].render)

    }//if(cvcam_properties[indexes[0]].render||cvcam_properties[indexes[1]].render)

   // MessageBox(NULL,"going run", NULL,MB_OK);
    _cvcamMediaControl->Run();
   // MessageBox(NULL,"ran", NULL,MB_OK);

    return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
/* Start the video */
CVCAM_API int cvcamStart()
{
    if(_cvcamNumberOfEnabled() == 2)
        return _cvcamStart2();

    vector<SafeUnknown> _objects;
    IBaseFilter* pProxyTrans = 0;
    _cvcamProxyTrans->QueryInterface(IID_IBaseFilter, (void**)&pProxyTrans);
    _objects.push_back(SafeUnknown(pProxyTrans));
    IPin* pProxyTransOut    = get_pin( pProxyTrans, PINDIR_OUTPUT );
    if(!pProxyTrans || !pProxyTransOut)
    {
        return -1;
    }

    if( !_cvcamMediaControl.is_valid() )
    {
        return -1;
    }

    int render;
    cvcamGetProperty(camera_index, CVCAM_PROP_RENDER, &render);
    if(render)
    {
        /* Get the window */
        HWND hWnd;
        cvcamGetProperty(camera_index, CVCAM_PROP_WINDOW, &hWnd);
        if(!hWnd)
        {
            hWnd = _cvcamCreateWindow();
            cvcamSetProperty(camera_index, CVCAM_PROP_WINDOW, &hWnd);
        }

        HRESULT hres = _cvcamVideoWindow->put_Owner((OAHWND)hWnd);
        long flags;
        hres = _cvcamMediaEventEx->SetNotifyWindow((OAHWND)hWnd, WM_GRAPHNOTIFY, 0);
        hres = _cvcamMediaEventEx->SetNotifyFlags(0x00);
        hres = _cvcamMediaEventEx->CancelDefaultHandling(EC_COMPLETE);
        hres = _cvcamVideoWindow->get_WindowStyle(&flags);
        hres = _cvcamVideoWindow->put_WindowStyle(flags & (~WS_CAPTION) | WS_CHILD);
        hres = _cvcamVideoWindow->put_MessageDrain((OAHWND)hWnd);

        // Get the rectangle dimensions and resize the client window
        AM_MEDIA_TYPE amt;
        pProxyTransOut->ConnectionMediaType(&amt);
        VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)amt.pbFormat;
        if(!vih)
        {
            return -1;
        }
        
        int rndheight = cvcam_properties[camera_index].rndheight?
            cvcam_properties[camera_index].rndheight:
            vih->bmiHeader.biHeight;


        int rndwidth = cvcam_properties[camera_index].rndwidth?
            cvcam_properties[camera_index].rndwidth:
            vih->bmiHeader.biWidth;
            

        _cvcamVideoWindow->SetWindowPosition( 0, 0, rndwidth, rndheight );
        const char* name = cvGetWindowName(hWnd);
        cvResizeWindow(name, rndwidth, rndheight);
    }

    _cvcamMediaControl->Run();
    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
/* Stop the video */
CVCAM_API int cvcamStop()
{
    if( _cvcamMediaControl.is_valid() )
    {
        OAFilterState fs;
        _cvcamMediaControl->GetState(0,&fs);
        if(fs == State_Stopped)
            return S_OK;
        
        
        _cvcamMediaControl->StopWhenReady();
        
       

        if(_cvcamVideoWindow.is_valid() )
        {
            _cvcamVideoWindow->put_Visible(OAFALSE);
            _cvcamVideoWindow->put_Owner(NULL);
            _cvcamVideoWindow->put_MessageDrain(0);
            
        }
        
        if(_cvcamVideoWindow2.is_valid() )
        {
            _cvcamVideoWindow2->put_Visible(OAFALSE);
            _cvcamVideoWindow2->put_Owner(NULL);
            _cvcamVideoWindow2->put_MessageDrain(0);
            
        }

        
        

        
        
        
        return 0;
    }
    else
    {
        return -1;
    }
}
/////////////////////////////////////////////////////////////////////////////////////////
/* Pause the video; should be used for preventing data changes during frame reading 
    using "frame" and other properties */
CVCAM_API int cvcamPause()
{
    if( _cvcamMediaControl.is_valid() )
    {
        OAFilterState fs;
        _cvcamMediaControl->GetState(0,&fs);
        if(fs == State_Stopped)
            return S_OK;
        _cvcamMediaControl->Pause();
    }   
    
    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
/* Resume the video */
CVCAM_API int cvcamResume()
{
    if( _cvcamMediaControl.is_valid() )
    {
        OAFilterState fs;
        _cvcamMediaControl->GetState(0,&fs);
        if(fs == State_Stopped)
            return S_OK;
        
        _cvcamMediaControl->Run();
    }

    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
/* Frees all resources */
CVCAM_API int cvcamExit()
{
    _cvcamSource.clear();
    _cvcamReset();
    _cvcamCreateDevEnum = 0;
    _cvcamEnumMon = 0;
    _cvcamMonikers.clear();
    cvcam_properties.clear();

    

    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////

CVCAM_API int cvcamBuildStereo()
{
    return -1;
}
/////////////////////////////////////////////////////////////////////////////////////////
/*Procedure for camera selection dialog*/
BOOL CALLBACK SelectionDlgProc(HWND hwndDlg, UINT message,
        WPARAM wParam, LPARAM lParam) 
{
    switch (message) 
    {
        case WM_INITDIALOG:
        {
            int n = cvcamGetCamerasCount();
            CameraDescription descr;
            HWND cbwnd = GetDlgItem(hwndDlg,IDC_COMBO1);

            

            for(int k = 0; k < n; k++)
            {
                cvcamGetProperty(k, CVCAM_DESCRIPTION, (void*)&descr);
                SendMessage(cbwnd,CB_ADDSTRING ,0,(LPARAM) descr.DeviceDescription);

            
            }

            return FALSE;
        }//case WM_INITDIALOG:

        case WM_COMMAND: 
        {
            switch(LOWORD(wParam))
            {
                case IDOK:
                {
                    
                    //get 1-st combo selection
                    int firstcmb = 
                        SendDlgItemMessage(hwndDlg, IDC_COMBO1,CB_GETCURSEL,0,0);
                    
                    if(firstcmb == -1)//nothing selected
                    {
                        EndDialog(hwndDlg, 0);
                        DestroyWindow(hwndDlg);
                        return TRUE;
                    
                    }//if(firstcmb == -1)
                    
                    //get 2-nd combo selection

                    HWND checkwnd = GetDlgItem(hwndDlg,IDC_CHECK1);
                    long ischecked = SendMessage(checkwnd,BM_GETCHECK,0,0);
                    int secondcmb;
                    if(ischecked == BST_CHECKED)
                    {
                        secondcmb =
                        SendDlgItemMessage(hwndDlg, IDC_COMBO2,CB_GETCURSEL,0,0);
                        
                        //consider we've deleted the 1-st combo selection
                        //from the second one's list
                        if(secondcmb>=firstcmb) secondcmb++;
                    
                    }//if (ischecked == BST_CHECKED)
                    else
                        secondcmb = -1;

                    //remember windows
                    vector<HWND> wnd;
                    for(int i = 0; i< cvcamGetCamerasCount(); i++)
                    {
                        HWND wnd1;
                        cvcamGetProperty(i, CVCAM_PROP_WINDOW, (void*)&wnd1);
                        wnd.push_back(wnd1);
                    }
                    
                    //reset cvcam
                    cvcamStop();
                    cvcamExit();
                    cvcamGetCamerasCount();

                    //apply settings
                    cvcamSetProperty(firstcmb,CVCAM_PROP_ENABLE, (void*)CVCAMTRUE);
                    cvcamSetProperty(firstcmb,CVCAM_PROP_RENDER, (void*)CVCAMTRUE);
                    

                    if(secondcmb!=-1)
                    {
                        cvcamSetProperty(secondcmb,CVCAM_PROP_ENABLE, (void*)CVCAMTRUE);
                        cvcamSetProperty(secondcmb,CVCAM_PROP_RENDER, (void*)CVCAMTRUE);
                        
                               
                    }

                    for(int j = 0; j< cvcamGetCamerasCount(); j++)
                    cvcamSetProperty(j, CVCAM_PROP_WINDOW, (void*)&(wnd[j]));

                    //init cvcam
                    if(!cvcamInit() )
                    {
                        MessageBox(0,"bad camera(s) or other error","cvcam error",
                                    MB_OK|MB_ICONERROR);
                        
                        return FALSE;
                    
                    }

                    //making the return value. HIWORD is 
                    //number of cams selected(1 or 2).
                    //HIBYTE of LOWORD is 1-st cam index
                    //LOBYTE of LOWORD is 2-nd cam index

                    int ncams = (secondcmb==-1)?1:2;
                    int result = MAKELONG(MAKEWORD(secondcmb,firstcmb),ncams);

                    EndDialog(hwndDlg, result);
                    //DestroyWindow(hwndDlg);
                    return TRUE;    
                    
                }

                case IDCANCEL:
                {
                    EndDialog(hwndDlg, 0);
                    //DestroyWindow(hwndDlg);
                    return TRUE;
                
                
                }

                case IDC_CHECK1://do we want a second camera?
                {
                    HWND checkwnd = GetDlgItem(hwndDlg,IDC_CHECK1);
                    long ischecked = SendMessage(checkwnd,BM_GETCHECK,0,0);

                    HWND secondcombo = GetDlgItem(hwndDlg, IDC_COMBO2);

⌨️ 快捷键说明

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