Post date: Feb 12, 2017 2:49:23 PM
Was avoiding this until I couldn't avoid it no more. Self-compiling OpenCV source with Nvidia Cuda so that I can get to see how the gpu works on OpenCV. The following are some of the better sites.
http://amin-ahmadi.com/2015/12/04/how-to-build-opencv-from-source-for-vc14/
http://funvision.blogspot.sg/2015/11/install-opencv-visual-studio-2015.html
and others.
First thing first, use the 2.4.x version of OpenCV. I tried with 3.2.0 and got something like 89 errors and 11 success. 2.4.13.2 gave me 66 successes 0 error 7 warnings first time round and even if you check online, you will find that the 2.4.x are recommended because they are a lot mopre stable especially if you want to rebuild everything from source up. I got the source code from
https://github.com/opencv/opencv/releases
One recommendation is to use GitHub. This looks okay too but when I ran it, I was going for the 3.2.0 version.
I am running Cuda 8.0.61 on an Intel i5 with 64-bit Windows 10.
If you don't already have it go to Cmake and get the 32-bit installer. Really don't know whether the 64-bit has anything to do with it but I switched around quite a lot and then found an online recommendation to get the 32-bit installer and after that I was on the right track.
Another piece of software that is worth getting is the 7-zip file manager. The files are so large that the Windows archiver are not very efficient. Also, this is one less thing you need to wait on.
After you install the Cmake, then run the Cmake gui. The top of the form allows you to input the Source directory and the Target build directory. The Source directory is the directory where you put the top level of the OpenCV source files i.e. where the first CMake files are. The Builds directory is where all the stuff that Cmake generates will be deposited. After you input these, select the C compiler from the Configure menu. There was a recommendation to manually specify the C and C++ compilers. That is what I did for my successful run. After you hit the Configure button and select the Compiler, Cmake will come up with information in the central window of the GUI. For me, I never managed to get these non-red and ran it with all red entries! The information displayed in the Cmake window is configuration information for the OpenCV Software so ensure that WITH_CUDA=ON is set. I did not need to set it as Cuda was installed on my system and the Cmake was smart enough to detect the installation. After Configure runs without any pop-ups, it is time to Generate the Visual Studio project files. Do this by hitting the GEnerate button next to the Configure button on the Cmake gui. When this is done, close Cmake and open your Visual Studio IDE.
With VS, open the OpenCV.sln file in the top level of the Builds directory. When loading is complete, hit the Rebuild button for the Debug version and then the Release version. Each of these builds take a very long time. I took about over 3 hours per compilation.
Now, after the two builds, the recommendation was to right-click on INSTALL in the Solution Explorer of the OpenCV project (below the OpenCV project file itself) and to do another Build. This is supposed to put the Debug and Release versions of the .lib's in the same directory. This didn't happen for me so I manually copied the Debug and Release versions into the lib directory. I also copied the Debug and Release versions of the equivalent .dll's in the same bin directory.
Under the Install directory on the top level, I found the Include directory and suitable lib and bin directories for my Debug and Release files. For OpenCV projects, the Install directory was my $(OPENCV_DIR) root which needs to be defined as an Environment Variable. In my case, this was C:\opencv-2.4.13.2\install
For OpenCV based projects, under C/C++ of the project properties menu, I had $(OPENCV_DIR)\include in the Additional Include Directories. Under Linker, I had $(OPENCV_DIR)\x64\vc14\lib under additional library directories. Under Additional Dependencies of the Linker Input, I put a list of all the (Debug) .libs starting with opencv_calib3d2413d.lib and ending with opencv_videostab2413d.lib. One more thing, version 2.x of OpenCV requires manually setting access to the .dll files. One way is to copy the required .dll's to the directory with the project executive. This is the way to make the project more portable. Another way which I took was to add to the Environment field of the Debugging form under the project properties the following : PATH=%PATH%;$(OPENCV_DIR)\x64\vc14\bin which is where all my .dll's are.