求教:控制摄像头

Darcy杨 2005-08-27 09:43:52
将摄像头截获的图像通过回调函数传给另一个程序(客户端),
为什么主程序的窗口被挡住,客户端的图像就不变了?
回调函数是在什么情况下得到图像的?

源代码:

void CCaptureServerDlg::OnBnClickedOk()
{//...
DWORD nID = m_dwSelected;

/* -- Create the capture window if we haven't done do. -- */
if (m_theVideoCapWnd.m_hWnd == NULL) {
m_theVideoCapWnd.CreateCaptureWindow(CString(""), WS_BORDER | WS_CHILD | WS_VISIBLE, CRect(38, 0, 124, 0), this, 0);
if (m_theVideoCapWnd.m_hWnd == NULL) {
MessageBox("Error: Can not Create Capture Window");
return;
}
}

/* -- Attempt to connect to driver. -- */
if (m_theVideoCapWnd.DriverConnect(nID) == FALSE) {
MessageBox("Error: Can not Connect to Driver");
return;
}
m_bConnected = TRUE;

/* -- Retrieve device parameters. -- */
CAPTUREPARMS capParms;
if (m_theVideoCapWnd.CaptureGetSetup(&capParms, sizeof(CAPTUREPARMS)) == FALSE) {
MessageBox("Error: Can not get setup parameter");
return;
}

/* -- Want separate thread. -- */
capParms.fYield = TRUE;
/* -- Do not abort when left mouse button is clicked. -- */
capParms.fAbortLeftMouse = FALSE;
/* -- Do not abort when right mouse button is clicked. -- */
capParms.fAbortRightMouse = FALSE;

/* -- Update device parameters. -- */
if (m_theVideoCapWnd.CaptureSetSetup(&capParms, sizeof(CAPTUREPARMS)) == FALSE) {
MessageBox("Error: Can not Set setup parameter");
return;
}

/* -- Get current state of capture window. -- */
if (m_theVideoCapWnd.GetStatus(&m_theCapStatus, sizeof(CAPSTATUS)) == FALSE) {
MessageBox("Error: Can not Get Status parameter");
return;
}

m_theVideoCapWnd.SetWindowPos(NULL, 0, 0, m_theCapStatus.uiImageWidth, m_theCapStatus.uiImageHeight, SWP_NOMOVE | SWP_NOZORDER);

/* -- Set preview rate. -- */
if (m_theVideoCapWnd.PreviewRate(33) == FALSE) {
MessageBox("Error: Can not Set Preview Rate");
return;
}

/* -- Turn on scaling. -- */
if (m_theVideoCapWnd.PreviewScale(TRUE) == FALSE) {
MessageBox("Error: Can not Turn on Scale");
return;
}

/* -- Start preview. -- */
if (m_theVideoCapWnd.Preview(TRUE) == FALSE) {
MessageBox("Error: Can not Start Preview");
return;
}

...
}

void CCaptureServerDlg::OnAccept()
{
//...
m_theVideoCapWnd.SetCallbackOnFrame(CCaptureServerDlg::FrameCallbackProc);
//...
}

控制摄像头的类是在CodeProject上面找到的,跟用API没什么大分别
...全文
131 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧