Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Qt support isn't needed if you use MFC. To display a cv::Mat into MFC control you have 2 way.

  1. Use GDI to transfer the image from OpenCV memory to DC of a CStatic Control like a Picture or Static Text. See a PkMatToGDI class on my web site and/or my old answer how-to-fix-resized-image-in-mfc for the code.
  2. Map a cvWindow over a MFC static control, as is your code, but with some correction.

try this:

const char * WIN_NAME_CV = "Histogram";
namedWindow(WIN_NAME_CV, CV_WINDOW_KEEPRATIO);
RECT rcDlg;        //ScreenToClient
HWND myhWnd = GetDlgItem(IDC_HISTOGRAM)->GetSafeHwnd();

// Or if you have the object for your static control
//HWND myhWnd = m_HistogramControl.GetSafeHwnd();

::GetWindowRect(myhWnd, &rcDlg);

int winWidth = rcDlg.right - rcDlg.left;
int winHeight = rcDlg.bottom - rcDlg.top;
HWND hWnd = (HWND)cvGetWindowHandle(WIN_NAME_CV);
HWND hParent = ::GetParent(hWnd);
::SetParent(hWnd, myhWnd);
::ShowWindow(hParent, SW_HIDE);
cvResizeWindow(WIN_NAME_CV, winWidth, winHeight);

Qt support isn't needed if you use MFC. To display a cv::Mat into MFC control you have 2 way.way:

  1. Use GDI to transfer the image from OpenCV memory to DC of a CStatic Control like a Picture or Static Text. See a PkMatToGDI class on my web site and/or my old answer how-to-fix-resized-image-in-mfc for the code.
  2. Map a cvWindow over a MFC static control, as is your code, but with some correction.

try this:this for 2nd way:

const char * WIN_NAME_CV = "Histogram";
namedWindow(WIN_NAME_CV, CV_WINDOW_KEEPRATIO);
RECT rcDlg;        //ScreenToClient
rcDlg;
HWND myhWnd = GetDlgItem(IDC_HISTOGRAM)->GetSafeHwnd();

// Or if you have the object for your static control
//HWND myhWnd = m_HistogramControl.GetSafeHwnd();

::GetWindowRect(myhWnd, &rcDlg);

int winWidth = rcDlg.right - rcDlg.left;
int winHeight = rcDlg.bottom - rcDlg.top;
HWND hWnd = (HWND)cvGetWindowHandle(WIN_NAME_CV);
HWND hParent = ::GetParent(hWnd);
::SetParent(hWnd, myhWnd);
::ShowWindow(hParent, SW_HIDE);
cvResizeWindow(WIN_NAME_CV, winWidth, winHeight);