網頁

2017年4月10日 星期一

[VideoInput] Download


Download VideoInput Libray from GitHub

https://github.com/ofTheo/videoInput to D://VideoInput
Extract
image

Synchronize project setting

image
image

Modification for Visual Studio 2015

VideoInput.cpp Line 821 as
        char * name =  (char*) videoInput::getDeviceName(i);

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

[OpenCV] Using static library in Visual Studio 2015 Console mode


Create Visual Studio 2015 console program

image

Add VideoCapture calls

#include "stdafx.h"
#include <opencv2/opencv.hpp>
int main()
{
    cv::Mat frame;
    cv::VideoCapture cap(0);
    if (!cap.isOpened()) {
        return -1;
    }
    while (true) {
        if (!cap.read(frame))
            break;
        cv::Mat src = cv::Mat(frame);
        cv::imshow("window", src);
        cv::waitKey(30);
    }
}

Add OpenCV include path

D:\OpenCV-3.2.0\opencv\build\include

Add OpenCV library path

D:\OpenCV-3.2.0\opencv\build\x86-static\lib\Release
D:\OpenCV-3.2.0\opencv\build\x86-static\3rdparty\ippicv\ippicv_win\lib\ia32
D:\OpenCV-3.2.0\opencv\build\x86-static\3rdparty\lib\Release

Add OpenCV library

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
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

Modify project configuration

image
image
image

Compile and Run

[OpenCV] 自行編譯 library for Visual Studio 2015

 

OpenCV 3.2.0 的安裝版本只有 X64 的 DLL 版本. 如果需要的不是這個版本, 就要自行編議. 譬如說, 主程式用到的是 X86 的編譯設定, 就需要 X86 的 DLL 版本. 如果不想要 release 的時候, 還要附帶一堆 DLL, 或是程式裡面已經用到了 /MT 的編譯選項, 那麼就要自行編譯 static library 的版本.

OpenCV 3.2.0 的 source code, 需要用 CMake 來做 configuration, 然後才能在 Visual Studio 2015 中編譯.

Download OpenCV 3.2.0 win pack

1. 下載 win pack (opencv-3.2.0-vc14.exe) from opencv.org

2. 解壓縮到硬碟中的任意目錄 : 這裡解壓縮到 D:\OpenCV-3.2.0image

Download CMake

1. 在 CMake 的網站下載安裝檔. Download Page, 他有 ZIP 版及 MSI 不同的安裝程式, 以及 32/64 的版本. 除了不要在 32 位元的系統上安裝 64 位元的版本外, 其他應該都沒有問題.

2. 安裝完之後, 會在程式列多一個 CMake 的目錄, 其中的 CMake( cmake-gui ) 就是稍後要來做 configuration 用的.

Configure build with CMake

1. 執行 cMake-gui
2. 設定 OpenCV 原始碼及目的碼的位置. source code 在解壓縮出來的目錄中, 目的碼最好另外指定. 以下指定為 build/x86-static, 名稱就是他的意思.
image
3. 按下 “configure” 開始設定, generator 選擇 VS 2015
image
4. 等待 configuration 結束
5. 清除選項中的 BUILD_SHARED_LIBS, 以編譯靜態連結版本
image

6. 按下 “generate” 開始產生 Visual Studio 2015 的專案檔案
7. 等待 …
image

用 Visual Studio 2015 編譯 OpenCV Library

1. 執行 VS2015, 並開啟  “OpenCV” solution file
image
2. Build Solution

這個 solution 中, 包含了 66 個專案, 所以要 build 一段時間, build 完會產生如下的檔案

image