網頁

2017年4月9日 星期日

[OpenCV] Using OpenCV static library in MFC application


Create MFC Application

image

Add Picture Control

image

Add Initial codes in OnInitDialog

// TODO:  Add extra initialization here
CRect rect;
CWnd *pWnd = GetDlgItem(IDC_LIVE);
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect); //optional step - see below
cv::namedWindow("IDC_STATIC_OUTPUT", 0);
cvResizeWindow("IDC_STATIC_OUTPUT", rect.right - rect.left, rect.bottom - rect.top);
HWND hWnd = (HWND)cvGetWindowHandle("IDC_STATIC_OUTPUT");
HWND hParent = ::GetParent(hWnd);
::SetParent(hWnd, GetDlgItem(IDC_LIVE)->m_hWnd);
::ShowWindow(hParent, SW_HIDE);
if (m_video.open(0))
{
    SetTimer(0, 33, NULL);
}


Add OnTimer Handler to drawing

image
void COpenCV_Static_MFCDlg::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    cv::Mat frame;
    m_video >> frame;
    cv::imshow("IDC_STATIC_OUTPUT", frame);
    CDialogEx::OnTimer(nIDEvent);
}
Update project setting
/Configuration Prperties/General
Use of MFC –> Use MFC in a Static Librar
Character Set –> Use Multi-Byte Character Set
/Configuration Properties/C/C++/Code Generation
Runtime Library –> Multi-thread (/MT)
Security Check –> Disable Security Check (/GS-)
/Configuration Properties/VC++ Directories
Include Directories: D:\OpenCV-3.2.0\opencv\build\include
Library Directires
image
/Configuration Properties/Linker/Input
Additional Dependencies
opencv_highgui320.lib
opencv_core320.lib
ippicvmt.lib
zlib.lib
opencv_imgproc320.lib
opencv_imgcodecs320.lib
IlmImf.lib
libjpeg.lib
libjasper.lib
libpng.lib
libtiff.lib
libwebp.lib
opencv_video320.lib
opencv_videoio320.lib
vfw32.lib

沒有留言:

張貼留言

請提供您寶貴的意見