Tuesday, January 16, 2018

Getting OpenCV to work with Visual C++ 2015 Build Tools


Who loves OpenCV, Windows & command line (Visual C++ 2015 Build Tools)? (raise my hand)
  1. Hope that everyone is using 64-bit version of Windows, since for 32-bit version of Windows, there is no official OpenCV version that just work.

    If in doubt, go to Start Menu/Settingsselect Systemin left panel select Aboutat right panel shows your System type is 64-bit operating system, x64-based processor, then you are good.
     
  2. Download & install Visual C++ Build Tools 2015
     
  3. Download & extract OpenCV Win pack, say, to C:\opencv
     
  4. Save following example code with filename you like, and extension cpp. Say, showimage.cpp at C:\showimage

    #include "opencv2/core.hpp"
    #include "opencv2/highgui.hpp"

    int main()
    {
        IplImage* img = cvLoadImage("orangeman.jpg");
        cvShowImage("Original", img);
        cvWaitKey(0);
        cvReleaseImage(&img);
        return 0;
    }
     
  5. Copy these OpenCV files to where your code at, C:\showimage
     
    C:\opencv\build\x64\vc15\lib\opencv_world340.lib
    C:\opencv\build\x64\vc15\bin\opencv_world340.dll
    C:\opencv\build\include\opencv2

     
  6. Go Start Menu/Visual C++ Build Tools, to use Visual C++ 2015 x64 Native Build Tools Command Prompt
     
  7. Navigate to your code at C:\showimage with the command.

    cd C:\users\ME\showimage
     
  8. Build .exe file from your code and the OpenCV files, with the command.

    cl showimage.cpp opencv_world340.lib
     
  9. You get showimage.exe, click and see.

No comments:

Post a Comment