内测

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,刚进去界面显示图形框是灰色的,就是这样
左上角没有相机
不用管它,只要点连续采集,程序运行就可以,结束运行也没用了,可以先不管它。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值