在MFC中加入Opencv的mat

1,在窗口初始化方法OnInitDialog()中添加以下代码

namedWindow("view", WINDOW_AUTOSIZE);

HWND hWnd = (HWND)cvGetWindowHandle("view");

HWND hParent = ::GetParent(hWnd);

::SetParent(hWnd, GetDlgItem(IDC_IMG)->m_hWnd);

::ShowWindow(hParent, SW_HIDE);

2,在显示图片的地方添加一下代码

Mat mat = imread("E:\\visual studio 2013\\Projects\\Kinect\\1.jpg", 0);

CRect rect;

GetDlgItem(IDC_IMG)->GetClientRect(&rect);

resize(mat, mat, Size(rect.Width(), rect.Height()));

imshow("view", mat);

3,注意

1,2两步中的view要一致

推荐阅读更多精彩内容