Hi everyone,
I’m trying to install OpenCV on my windows 10 machine for academic purpose. I have to follow an installation guide provided by my professor, that requires VisualStudio 2017 and Cmake. I have done literally any point of that guide, that I report -brielfy- here:
Install VisualStudio 2017 and Cmake
Download (from github) opencv-3.3.1 and opencv_contrib-3.3.1 and unzip them into a folder ‘source’ (created before together with another folder ‘build’ inside another folder ‘C:\workspace’)
Use Cmake (Source code: …opencv3\source\opencv, where to build: opencv3\build). Generator: VisualStudio 15 2017 Win64.
When Cmake finishes, look for “OPENCV_EXTRA_MODULES_PATH” and set it to your opencv_contrib/modules path.
Press Configure and then Generate
Open the OpenCV.sln file with VisualStudio, change to Release the build type, then find the INSTALL project inside CMakeTargets folder and build it.
Now, I need to add to the environment variables a new variable OPENCV_DIR with value …\opencv3\build\install\x64\vc15
Now…the problem is that, inside the install folder, there’s NO x64 DIRECTORY, and I cannot find ANY vc15 DIRECTORY in the entire build folder… I really don’t know how to proceed, since I’ve been looking for a solution for at least 3 hours… Is there anyone that would kindly help me?
Thanks in advance (and sorry if I did s.thing wrong in creating the topic)
This is the content of the directory, and…yes, the build completed without any error or warning, and I’m 100% sure I built the INSTALL target under CMakeTargets folder
It looks like the locations for OpenCV 3 are different to 4. Because I am not sure how your OPENCV_DIR variable will be used, I cannot tell you conclusively which directory to set it to. In OpenCV 4 the
directory contains the lib and bin folder. If the OPENCV_DIR is just used for that then you can set it to
…\opencv3\build\install\
However I suspect that OPENCV_DIR could also used to locate the include directory so you may find some of your projects have something similar to
..\..\include
in the project properties, C/C+±>General->Additional Include Directories. In that case you would need to remove the proceeding …..\ and just leave include
Not sure why you are adding %OPENCV_DIR%\lib as well as %OPENCV_DIR%\bin maybe cmake etc. picks up the lib paths in your project. Either way the above should work.
However, I set …\opencv3\build\install\ as value for OPENCV_DIR, and still nothing works. I’m compiling a sample project provided by my professor, saved as .cpp, that has only the directive:
#include <opencv2\highgui.hpp>
by using cmd:
g++ -o [file] lopencv_highgui -lopencv_core
and the result is always “no such file or directory bla bla bla”… but inside \build\install\include\opencv2 I can find the library highgui.hpp, indeed.
I tried also to modify the OPENCV_DIR variable according to the path were the .hpp file is, but nothing changes
It looks like the OPENCV_DIR variable is being used to detect the headers as well as I suspected in my previous post. Therefore you will need to find where it is referenced, probably something like
%OPENCV_DIR%\..\..\include
and change it to
%OPENCV_DIR%\..\..\include
Just out of interest are you building your project on linux or using g++ on windows?
If you want you can just change
#include <opencv2\highgui.hpp>
to the actual path where highgui.hpp is to check that this is your only issue.
C:\workspace\opencv3\build\install\include\opencv2
This is the path where all the headers are located. I tried to modify OPENCV_DIR with this, and I changed %OPENCV_DIR%\bin %OPENCV_DIR%\lib
to just %OPENCV_DIR%
but still nothing.
So I tried also to define OPENCV_DIR as: C:\workspace\opencv3\build\install
and then add to path variable %OPENCV_DIR%\include\opencv2
but this was useless.
And also changing the directive with: #include <highgui.hpp>
HOWEVER…
I wrote #include <C:\workspace\opencv3\build\install\include\opencv2\highgui.hpp> and this seems to correctly include highgui.hpp, but then the compiler tells me: C:\workspace\opencv3\build\install\include\opencv2\highgui.hpp:46:28: fatal error: opencv2/core.hpp: No such file or directory #include "opencv2/core.hpp"
This means that highgui was found, but now it doesn’t find core.hpp (that is included INSIDE highgui, as I see)
Is the project you are building fixed or do you use cmake to generate it?
If its fixed, somewhere in your configuration the path to C:\workspace\opencv3\build\install\include\
will be specified, probably as %OPENCV_DIR%\..\..\include
If you are unable to find it I would suggest manually adding C:\workspace\opencv3\build\install\bin\
and C:\workspace\opencv3\build\install\lib\
to your user path. That way the executable can find the opencv dll’s when you run it and if you have another project that autodetects the libs using a cmake or other script they will be on the path.
Then set OPENCV_DIR to C:\workspace\opencv3\build\install\x64\vc15
I know it doesn’t exist but the headers should be found.
Then you will probably find that your lib’s won’t be detected as they are probably also relative to OPENCV_DIR.
just for the sake of completeness: C:\workspace\opencv3\build\install includes 4 directories: bin, with .exe and .dll files lib, with .lib and some .cmake files etc, only .xml include, with opencv2 folder inside, which has .hpp files and some other folders (among these also a directory ‘highgui’ with a different highgui.hpp and a highui_c.h).
Now I wonder if I’m looking at the wrong directory