Ok, so I figured out and I have it working in both C++ and C# depending on which language you prefer.
Here are the steps for each, and if you’re curious how I debugged it, I described what I did below. Note that I’m in Visual Studio Pro, not Express so certain options might be in different places.
Let me know if this still doesn’t work….
-
Download latest stable version of OpenCV (I used 2.4.2) http://sourceforge.net/projects/opencvlibrary/files/latest/download?source=files
-
Extract it to the folder you want OpenCV in (you will reference this folder later, so don’t just keep it in downloads)
-
Open up the command prompt, run “cmake .” in the OpenCV folder you just extracted. A bunch of new files should appear
-
Open up the OpenCV.sln file in Visual Studio
-
Switch to “Debug” or “Release” mode depending on which you want. “Debug” is a bit slower but it will make it easier to…. Well… debug... but use release if you plan on putting it in production. It’ll remove all the debug lines, etc.
-
Updated PATH environment variable to include “<path_to_extracted_openCV>\bin\Debug” and removed anything that corresponded to the previous attempt to make this work
-
Create a new project (C++, Win32 console)
-
In your project (in Visual Studio)… Visual Studio (note that this is only for debug mode, you’d have to do the same but with the “Release” for release mode builds 1. Under VC++ Directories in Project Properties:
- Update “include directories” to include “<path_to_extracted_openCV>\build\include”
- “Library Directories” to include “<path_to_extracted_openCV>\lib\Debug”
- “Source Directories” to include
“<path_to_extracted_openCV>\modules; <path_to_extracted_openCV>\modules\core; <path_to_extracted_openCV>\modules\highgui; <path_to_extracted_openCV>\modules\ml;$(SourcePath)”
And of course, include more modules if your code requires it. 2. Under Linker > Input
- Additional Dependencies: “opencv_legacy240d.lib;opencv_core240d.lib;opencv_highgui240d.lib;%(AdditionalDependencies)”(And add more dependencies if your code requires it)
Link to my Hello World solution (note paths in references might be different on your computer)
EmguCV is a C# wrapper, and this one is easier. And C# is a nicer language, especially if you already know Java well.
I had a few issues with this until I found this link: http://www.codeproject.com/Articles/257502/Creating-Your-First-EMGU-Image-Processing-Project
And use Emgu version 2.3 – I had problems with 2.4 because I’m using Windows 8 but you’ll also have problems with Visual Studio 2012 on Windows 7 I believe. 2.3 is safer. Choose x86 or x64 binaries depending on which architecture you’re TARGETING
If you want to run the code on multiple platforms (non-Windows machines), look into Mono. EmguCV is compatible with it, and many high profile cross-compatible apps have been built using the Mono framework.
Link to my Hello World solution (note paths in references might be different on your computer): http://sdrv.ms/XZwoAJ
- Free visual studio pro for students: https://www.dreamspark.com/
- Free everything else Microsoft… ask me J
C++… so this was actually kind of fun to debug and I wanted a record of what I did, so I wrote it out, but I figured I might as well share rather than making it look like magic J. First I reproduced your problem. I went, downloaded the .exe binaries for OpenCV 2.2, and added the .lib files etc. to the Visual Studio linker.
I ran the OpenCV hello world application in debug mode in visual studio to no avail. The message was a little cryptic, didn’t point to any line in the code, so it wasn’t likely that and had more to do with the configuration.
Under “additional dependencies” in the OpenCV_HelloWorld, recall that you added a bunch of lines like “opencv_core220d.lib”. Notice the “d” at the end. This means that they are the debug libraries. So first thing I tried was just switching it to the non-debug libraries by removing the ‘d’
It worked.
Okay, now we could stop there, but it’s kind of a pain not to be able to dig into the code if it’s not working. So I tried to figure out why the debug libraries weren’t working.
Next, I ran a tool called “Dependency Walker” on the .exe generated by running in debug mode.
I tried it on the .exe generated in release mode (the one that did work), and didn’t have the side-by-side configuration errors.
Hmm… side-by-side configuration…. http://www.codeproject.com/Articles/43681/Side-by-Side-Configuration-Incorrect
That led me to a tool called SxSTrace that ships with Visual Studio Command Line tools.
I opened up the file and one part in particular caught my interest
I looked up Microsoft.VC90.Debug.CRT, turns out that’s a Visual Studio 9.0 thing (VS2008) and I had Visual Studio 10.0, 11.0 DLLs on my system.
First I tried just finding the 9.0 dll but realized that it was going to be getting too hacky and might cause other problems down the line.
That’s when I switched to using CMake. I downloaded and installed CMake, making sure to check the box to include it in the current user path. I ended up downloading both 2.8 and 2.6 because I read it somewhere but 2.8 only probably would have worked on its own. Downloaded and extracted OpenCV 2.4.2, extracted it… “cmake .”, which produced a .sln file, OpenCV.sln…. opened this file, built it IN visual studio using the VC++ compiler in DEBUG mode. I went back to the folder I’d extracted OpenCV too, and found a couple new directories generated (the ones that get generated whenever you build any program) – “bin” and “lib”.
If you open bin and lib, there will be one or two folders – “debug” and “release” depending on which mode you built in.
From here I did a few things to start using the new libraries. I found all this out mainly by comparing the two OpenCV attempts, and mapping the folders in the previous attempt to the folders in the new attempt:
- Updated PATH environment variable to include “<path_to_extracted_openCV>\bin\Debug” and removed anything that corresponded to the previous attempt to make this work
- In Visual Studio (note that this is only for debug mode, you’d have to do the same but with the “Release” for release mode builds
1. Under VC++ Directories in Project Properties:
- Update “include directories” to include “<path_to_extracted_openCV>\build\include”
- “Library Directories” to include ““<path_to_extracted_openCV>\lib\Debug”
- “Source Directories” to include “<path_to_extracted_openCV>\modules; <path_to_extracted_openCV>\modules\core; <path_to_extracted_openCV>\modules\highgui; <path_to_extracted_openCV>\modules\ml;$(SourcePath)” And of course, include more modules if your code requires it. 2. Under Linker > Input
- Additional Dependencies: “opencv_legacy240d.lib;opencv_core240d.lib;opencv_highgui240d.lib;%(AdditionalDependencies)”
And tada! It works!