SingleGrabDlg.cpp
函数 BOOL CGCapDlg::OnInitDialog()
整个替换为
BOOL CGCapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
ShowWindow(SW_MAXIMIZE);
// 初始化相机函数库
MVInitLib();
// 打开相机
OpenCamera();
CRect rc;
CWnd *pWnd = GetDlgItem(IDC_DISPLAY_IMAGE);//参数为控件ID
pWnd->GetClientRect(&rc);//rc为控件的大小。
int py = rc.Height();
int px = rc.Width();
//获取窗口大小
CRect _GetGroup;
this->GetClientRect(_GetGroup);
int y = _GetGroup.Height();
int x = _GetGroup.Width();
cvNamedWindow("result", CV_WINDOW_AUTOSIZE);
HWND hwnd = static_cast<HWND>(cvGetWindowHandle("result"));
HWND parent = ::GetParent(hwnd);
::SetParent(hwnd, GetDlgItem(IDC_DISPLAY_IMAGE)->GetSafeHwnd());
::ShowWindow(parent, SW_HIDE);
//设置控件位置
pWnd->MoveWindow(x - 900, y - 800, 640, 480);
return TRUE; // return TRUE unless you set the focus to a control
}
函数 void CGCapDlg::EnableButton()
整个替换为
void CGCapDlg::EnableButton()
{
GetDlgItem(IDC_SINGLE_GRAB)->EnableWindow(!m_bRun);
GetDlgItem(IDC_FREE_RUN)->EnableWindow(!m_bRun);
GetDlgItem(IDC_STOP)->EnableWindow(m_bRun);
GetDlgItem(IDC_STARTRUN)->EnableWindow(m_bRun);
GetDlgItem(IDC_ENDRUN)->EnableWindow(m_bRun);
}
显示图像时直接用iimshow函数就可以了,不用再加waitkey和destroyallwindow了,就像这样
resize(src, src, Size(640, 480));
imshow("result", src);
/*这一行一定要加进去,加进去相机才会连续拍摄*/
MVStartGrab(m_hCam, StreamCB, (ULONG_PTR)this);
另外找一下你的 void CGCapDlg::OnBnClickedStartrun() 函数,里面有一段这样的代码
cvNamedWindow("result", CV_WINDOW_AUTOSIZE);
HWND hwnd = static_cast<HWND>(cvGetWindowHandle("result"));
HWND parent = ::GetParent(hwnd);
::SetParent(hwnd, GetDlgItem(IDC_DISPLAY_IMAGE)->GetSafeHwnd());
::ShowWindow(parent, SW_HIDE);
//设置控件位置
pWnd->MoveWindow(x - 900, y - 800, 640, 480);
整个删掉它,具体代码是啥不清楚,但是很类似,你把那一块都删了
剩下的不动,这样应该就可以连续抓单帧的图像了。有一个小bug,刚进去界面显示图形框是灰色的,就是这样
不用管它,只要点连续采集,程序运行就可以,结束运行也没用了,可以先不管它。