我写了一个用双目同时采集视频,捕获图像的基于对话框的程序,但在初始化两个摄像头的时候遇到了问题:
初始化部分的代码如下:
BOOL CGSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
    m_bInit=FALSE;
    m_nBit=0;

    CAPTUREPARMS m_Parms,m_Parms1;
    
if(!m_wndSource.CreateEx(WS_EX_TOPMOST, NULL, "视频源窗口1",
         WS_CAPTION,CRect(200,200,840,680),NULL,0))
             return -1;       m_hCapWnd1=capCreateCaptureWindow((LPCTSTR)TEXT("视频捕捉程序"),
                    WS_CHILD|WS_VISIBLE,
0,0,640,480,
m_wndSource1.m_hWnd,0);  //设置预示窗口
  m_wndSource.ShowWindow(SW_SHOW);
ASSERT(m_hCapWnd);
if(capDriverConnect(m_hCapWnd,0))
{
//连接第0号驱动器
m_bInit=TRUE;
//得到驱动器性能


capDriverGetCaps(m_hCapWnd,sizeof(CAPDRIVERCAPS),&m_CapDrvCap);
        
if(m_CapDrvCap.fCaptureInitialized)
{
//如果初始化成功
capGetStatus(m_hCapWnd,&m_CapStatus,sizeof(m_CapStatus)); //得到驱动器状态
capCaptureGetSetup(m_hCapWnd,&m_Parms,sizeof(m_Parms));
m_Parms.dwRequestMicroSecPerFrame=66667/2;
capCaptureSetSetup(m_hCapWnd,&m_Parms,sizeof(m_Parms));

capPreviewRate(m_hCapWnd,66);   //设置预示祯频
//capPreviewScale(m_hCapWnd,TRUE);  //设置预示范围
capPreview(m_hCapWnd,TRUE);  //设置预示方式
}
else
{
AfxMessageBox("初始化失败");
AfxGetMainWnd()->PostMessage(WM_CLOSE); }
}
else
{//未能连接到驱动器
    AfxMessageBox("初始化失败");
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
//////////////////////////////////////////////////////////////////////////////////////           
///////////////第二个捕获窗口         
     if(!m_wndSource1.CreateEx(WS_EX_TOPMOST, NULL, "视频源窗口2",
         WS_CAPTION,CRect(100,100,840,680),NULL,0))
             return -1;
      m_hCapWnd1=capCreateCaptureWindow((LPCTSTR)TEXT("视频捕捉程序"),
                    WS_CHILD|WS_VISIBLE,
0,0,640,480,
m_wndSource1.m_hWnd,0);  //设置预示窗口
  m_wndSource1.ShowWindow(SW_SHOW);           ASSERT(m_hCapWnd1);
          if(capDriverConnect(m_hCapWnd1,1))
  {
           //连接第0号驱动器
                m_bInit=TRUE;
                 //得到驱动器性能


           capDriverGetCaps(m_hCapWnd1,sizeof(CAPDRIVERCAPS),&m_CapDrvCap1);
        
                  if(m_CapDrvCap1.fCaptureInitialized)
{
                //如果初始化成功
                 capGetStatus(m_hCapWnd1,&m_CapStatus1,sizeof(m_CapStatus1)); //得到驱动器状态
                  capCaptureGetSetup(m_hCapWnd1,&m_Parms1,sizeof(m_Parms1));
m_Parms.dwRequestMicroSecPerFrame=66667/2;
    capCaptureSetSetup(m_hCapWnd1,&m_Parms1,sizeof(m_Parms1));
    capPreviewRate(m_hCapWnd1,66);   //设置预示祯频
              capPreviewScale(m_hCapWnd1,TRUE);  //设置预示范围
                capPreview(m_hCapWnd1,TRUE);  //设置预示方式
}
                    else
{
                    AfxMessageBox("初始化失败");
                    AfxGetMainWnd()->PostMessage(WM_CLOSE); }
  }
      else
  {//未能连接到驱动器
              AfxMessageBox("初始化失败");
          AfxGetMainWnd()->PostMessage(WM_CLOSE);
  }

// Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE;  // return TRUE  unless you set the focus to a control
}编译无误,但是程序运行时总是提示“初始化失败”,是不是我的程序写的不对。
我刚刚开始接触VC++,程序写的很“拙”,希望能得到大家的指点。非常感谢。