Tuesday, July 15, 2014

OpenCV: Downloading OpenCV

StartOpenCV.html

Getting OpenCV onto Windows 7 and Visual Studios 2013

Downloading OpenCV


To begin, I downloaded the OpenCV package from the OpenCV download page . This package includes everything you need to use unless you had plans for unique third party libraries in an .exe file for windows. Generally, you follow the steps listed in the tutorial Installation to Windows which indicate that you just need to download the file, move the file to a drive (like C:\) directly for typing purposes later, and link the path to your respective file. Mine was C:\OpenCV\Build\x86\vc12. To clarify, I used an x86 build because this is the version of Visual Studios I had, not the version of Windows OS. If you want, for some reason, to change your Visual Studios type, here is the link. In Windows 7 command line, a confirmation response "SUCCESS: Specified value was saved" was displayed.

Working with Microsoft Visual Studios 12 2013 and OpenCV 2.8X

Once downloaded, you can follow the next tutorial How to build applications with OpenCV inside the Microsoft Visual Studio for further instructions. One part I had done differently was that under both debug and release property pages, in Linker → General, I had to also change "Use Library Dependency Inputs" from No to Yes thanks to Stack Overflow . This is all you need to do for OpenCV version 2.8X.

Working with Microsoft Visual Studios 12 2013 and OpenCV 3.0X OpenCV 3.00

Here is the OpenCV 3.0 dev documentation. I will say explicitly that this is a windows 7 64 bit machine and I downloaded the OpenCV 3.0 file updated 2015-06-04. Problems and methods that I used here may not apply to your own problems. I highly suggest googling help links in stackoverflow for opencv. There are additional steps are required to download OpenCV 3.0 compared to the steps above.

Firstly, the files that were in the lib folder in OpenCV 2.8X are now in the static library folder (staticlib). Thanks to MadeofAir on the OpenCV forums for answering the question, you must link not to lib, but to staticlib folder. Additionally, the linked libraries are different. Instead of the list mentioned in this linked tutorial , using the following list:
IlmImf.lib
ippicvmt.lib
libjasper.lib
libjpeg.lib
libpng.lib
libtiff.lib
libwebp.lib
opencv_calib3d300.lib
opencv_core300.lib
opencv_features2d300.lib
opencv_flann300.lib
opencv_hal300.lib
opencv_highgui300.lib
opencv_imgcodecs300.lib
opencv_imgproc300.lib
opencv_ml300.lib
opencv_objdetect300.lib
opencv_photo300.lib
opencv_shape300.lib
opencv_stitching300.lib
opencv_superres300.lib
opencv_video300.lib
opencv_videoio300.lib
opencv_videostab300.lib
zlib.lib
    
For the Debug Project Sheets, after the version number, there is a letter 'd' for debug. Note that ippicvmt.lib does not have a "ippicvmtd.lib" file. In the debug file, simply use the "ippicvmt.lib" name file. This solved my LNK2019 LNK2001 LNK1120 errors.

Secondly, thanks to yzt, user1043413, and other links or forum articles, you should quickly realize that following the tutorials in the official OpenCV website is currently incorrect because the libraries are set up to be static libraries instead of dynamic libraries in the previous verison. This should solve your LNK2038 errors with "mismatch detected for 'RuntimeLibrary':value 'MTd_StaticDebug' doesn't match value 'MD_DynamicRelease' in Run.obj" and associated issues.

For me this was the last of my errors, and I was able to successfully build the example code in the tutorials. If your compile does not work, I saw common issues were people using the wrong bit and not including all the libraries. If you do want to have a dynamic linked library (DLL), then you need to follow the Installation by Making Your Own Libraries from the Source Files processes. Since I was able to download the pre-made libraries in sourceforge correctly, I did not go through the process of downloading the custom libraries.

Working with Microsoft Visual Studios 14 (2015) and OpenCV 3.01 with CMake

At this time, February 12, 2016, downloading OpenCV through the usual .exe file from the OpenCV website seemed to have some unanswerable problems. Instead, I tried downloading through using CMake, which makes the OpenCV package from the source files. My information largely comes from this stackoverflow question answered by globalex and Vlada Kucera , the steps are largely listed.
1. Download CMake
2. Download Source Code of OpenCV and extract the zip file (results in a folder ".../opencv-master"
3. Open CMake, choose the opencv-master file as your souce code and underneath, choose where you want to build the binaries (usually in C:/OpenCV")
4. Configure CMake by choosing the compiler for you (in this tutorial, Visual Studio 14 2015) with "Use default native compilers" checked. When you hit finish, CMake will generate the binaries (otherwise hit generate). You should be online for CMake to download some library files.
5. In the newly generated binary files, there is a file called "OpenCV.sln." Open the file using Visual Studios 2015.
6. First, in the toolbar, hit Local Windows Debugger with Debug and Win32 in the boxes next to the Debugger icon. VS should take a while to run through all the OpenCV files in your binaries.
7. After, click the drop down menu for Debug, and select Release. Run the Local Windows Debugger again.
8. Next, go to project INSTALL under folder "CMakeTargets" in VS and Build/Local Windows Debugger when the build is in Release. After, VS will ask you to rebuild ALL_BUILD again. I chose to rebuild all, though I have no knowledge if the rebuild option is any better or worse.
9. Following closely with what the OpenCV tutorial, I set the environmental variable in command line with administrator purposes "setx -m OPENCV_DIR C:\OpenCV\Install\x86\vc14" and set in my system PATH "%OPENCV_DIR%\bin" for the library files to find the Dynamica-Linked Libraries (DLL). Follow the docs.opencv.org tutorials to change the appropriate sections in the Property Sheets. The files in the linked library are:
opencv_calib3d310.lib
opencv_core310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_photo310.lib
opencv_shape310.lib
opencv_stitching310.lib
opencv_superres310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
    


Issues:
Step 7:
If you get error like "Unable to start program C:\OpenCV\ALL_BUILD Cannot find the specified file," according to this question on answers.opencv.org, answered by Cristina, "ALL_BUILD is not a program, it's just a target that perform build of all other targets." In your Solution Explorer window/pane, right click on a project you want to start (in the forum, opencv_test_core was the example), right click the project, and select "Set as StartUp Project."
Also, if you ever get a "The program can't start because opencv_core310.dll is missing," it is because you did not set the PATH (%OPENCV_DIR%\bin) correctly, and VS cannot find the .dll files because it has no way of knowing where they are (Thanks to a stackoverflow answer by udith).
Step 9
If you made a project before you changed the system variables, according to a multitude of forums (1, 2, 3, 4), VS does heavy caching and the project most likely has the value of your environmental variable incorrect (at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\...). I did not bother to find where the environmental variables were stored and manually change it, and instead deleted and recreated the project since it I had done nothing significant with it.

What's Next

I plan to go through the OpenCV Tutorials and post any small tutorial projects.Learning OpenCV code is tandem to my project of robot vision in autonomous vehicles. Executing the sample code listed above will be on the next blog post here.

No comments:

Post a Comment