FlagVideoWindow保证opencv windows 与 picture control不会重复关联,IDC_PHOTONAME1为picture control名称:
if (FlagVideoWindow)//此段代码近执行一次 { FlagVideoWindow = false; CRect rect; GetDlgItem(IDC_PHOTONAME1)->GetClientRect(rect); namedWindow("摄像头画面", WINDOW_NORMAL); resizeWindow("摄像头画面", rect.Width(), rect.Height()); HWND hWnd = (HWND)cvGetWindowHandle("摄像头画面"); HWND hParent = ::GetParent(hWnd); ::SetParent(hWnd, GetDlgItem(IDC_PHOTONAME1)->m_hWnd); ::ShowWindow(hParent, SW_HIDE); } camera.open(0); if (!camera.isOpened()) { AfxMessageBox(_T("Camera_Open failed!")); exit(1); } while (1) { camera >> cameraFrame; if (cameraFrame.empty()) { //AfxMessageBox("Camera_Show failed!"); exit(1); } imshow("摄像头画面", cameraFrame); if (waitKey(30) >= 0) break; }