Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a image in a MFC/C++ application using OpenCV

Tags:

c++

opencv

mfc

I would like to display in a MFC application, frames that I capture from an avi file with OpenCV (cvCaptureFromAVI function).

I'm new to MFC but feel like I'm close to making it work. But instead of the frames being displayed in the picture box they are displayed in a new window.

cvGetWindowName returns always a null value.

There is my code:

CWnd* hPic = 0;
hPic = GetDlgItem(IDC_STATICPIC1);  
const char* szWindName = cvGetWindowName(hPic->GetSafeHwnd());
cvShowImage(szWindName, frame_copy);
like image 875
david Avatar asked Oct 15 '25 17:10

david


1 Answers

So I found something to make it work after long researches.

The solution is to create the window and then insert it inside the picture box. I'm not sure it's good practice but I haven't found anything better for now.

cvNamedWindow("IDC_STATIC_OUTPUT", 0); 
cvResizeWindow("IDC_STATIC_OUTPUT", 420, 240);

HWND hWnd = (HWND) cvGetWindowHandle("IDC_STATIC_OUTPUT"); 
HWND hParent = ::GetParent(hWnd); 
     ::SetParent(hWnd, GetDlgItem(IDC_PIC1)->m_hWnd); 
     ::ShowWindow(hParent, SW_HIDE); 

cvShowImage("IDC_STATIC_OUTPUT", frame_copy);

In this case the picture box is called IDC_PIC1 and frame_copy is a OpenCV IplImage.

Hope this helps somebody.

like image 189
david Avatar answered Oct 17 '25 18:10

david