21

I want to use OpenCV in Visual Studio 2017 to do c++ program.

To do it, I followed Setting Up OpenCV in Visual Studio video. In that, he said vc14 should be set as environmental variables for VS2015. There is no vc16 for VS2017. So how do I do it for VS2017? And are there any other video instruction changes to be made if I am to use VS2017?

8
  • ummm are you generating the code using cmake right? Commented May 4, 2017 at 15:18
  • @ΦXocę웃Пepeúpaツ No. I am just following the instructions from the video. Commented May 4, 2017 at 15:20
  • 1
    Instead of following the advice of random strangers on YouTube, why don't you follow the instructions in the OpenCV documentation? Commented May 4, 2017 at 15:24
  • 2
    @BoundaryImposition OpenCV documentation is out-dated. I want for VS2017 but the document is about VS2012. Commented May 4, 2017 at 15:28
  • 1
    hold on... am writing how Commented May 4, 2017 at 15:41

3 Answers 3

41

Since the Doc from official OpenCV tutorial is outdated, I will suggest:

  1. get VS-2017 with full compiler like:

    enter image description here

  2. get the newest CMake (uninstall older versions)

  3. get from github the sourceCode here and here and place those in C:/openCV folder, create a BUILD folder there too

  4. open Cmake, select the opencv master folder... in the build write the build directory like:

enter image description here

  1. click configure, select visual studio 15 2017 and leave selected "use default native compilers", then press "finish"...

enter image description here

6.1 now you should see cmake doing its job :)

enter image description here

  1. once configuration is done set the opencv extra modules path and click configure again, and when is done click generate! :)

    enter image description here

  2. when generation is done click "open project", this will open a huge project in visual studio named "opencv", now you can close cmake, we dont need that anymore.

  3. now, when the solution is ready, be sure you are in "debug" conf and do right click on "ALL_BUILD" and then "build" (that can take a while) once build succeed change to "release" config and do right click on "ALL_BUILD" and then "build" again.

  4. now,be sure you are in "debug" conf and do right click on "INSTALL" and then "build" (that can take a while) once build succeed change to "release" config and do right click on "INSTALL" and then "build" again.

16
  • I just had too many bugs from 3rd party libs and tried to make with PCL (Point Clouds Library). So got back to Visual Studio 2015, since i am beggining to learn. stackoverflow.com/questions/43902133/… Commented Jun 21, 2017 at 14:01
  • 1
    had to downvote both answers, i spend 40 mins following instruction but no one gave an idea of the name/ path of things to include, and now my IDE is full of "not found" error messages, what do we include?! (i.e. #include <> or "" or opencv or opencv2 ....???)
    – aero
    Commented Dec 11, 2017 at 18:26
  • 1
    What about linking and including the path to \include-path? Do I have to do that anyway? Because in VS I get error "E1696: cannot open source file "opencv2/opencv.hpp" "
    – sequoia
    Commented Oct 28, 2018 at 11:01
  • 1
    If installing with CUDA in step 5 select x64 Commented Apr 18, 2019 at 20:43
  • 1
    Followed the steps and everything was right. Then, running a program that needs opencv, got the following error:learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/… "cannot open include file 'opencv2/opencv.hpp':no such file or directory"
    – dtr43
    Commented Nov 4, 2019 at 17:17
3

Additonal tip to the accepted answer - if you get an error like this:

Invalid escape sequence \ o

when you copy and paste the filesystem paths, make sure you use forward slash ( / ) instead of backward slash, so

C:\openCV\opencv_contrib-3.2.0\modules

Must be

C:/openCV/opencv_contrib-3.2.0/modules

Instead. Otherwise, you will get errors that escape sequence \o does not exist.

1

Previous post is just perfect. VS 2017 has lib version VS141.

Just extension of previous.

8 Step. After the cmake generate the Opencv.sln in build folder. Open this project in VS 2017 Opencv visual studio 2017

I am using approach first, just DEBUG x64 version

Opencv visual studio 2017

The output looks like this

Opencv visual studio 2017

After Debug, switch to Release and Build whole solution again. Same for 32 bit version. Your final solution is under install location under build folder. With contrib libs whole process took almost 30 minutes on I7. Just shaking with CMAKE until the zero defects, include what ever FFMPEG, Contrib and other path. Final build in VS 2017.

The whole approach and install of built libs you can find on my blog Here

4
  • 1
    I don't know why I don't find x64 option in debug like in this step you mentioned in your blog: "FIRST just select DEBUG, x64 version like on picture, click right mouse on Entire solution and hit BUILD solution like on picture."
    – SarahData
    Commented Jul 28, 2017 at 21:03
  • Hi @globalex. I can successfully build opencv with VS2017. And my project compile perfectly. But videocapture doesn't function normally in debug mode. In release mode, everything works fine.
    – Tim Hsu
    Commented Nov 27, 2017 at 12:18
  • had to downvote both answers, i spend 40 mins following instruction but no one gave an idea of the name/ path of things to include, and now my IDE is full of "not found" error messages, what do we include?! (i.e. #include <> or "" or opencv or opencv2 ....???)
    – aero
    Commented Dec 11, 2017 at 18:26
  • @aero. How we can cover all your mistakes in this steps? It works.. Tim Hsu, you need to build opencv with ffmpeg to let video capture works.. Depends also capture of what and the platform. But in general FFMPEG
    – globalex
    Commented Dec 18, 2017 at 20:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.