views:

1811

answers:

2

I am trying to setup OpenCV 2.0 for Visual C++ Express but I can not do it successfully. I have looked all over the internet and have tried the official guide. Can someone guide me to a tutorial that worked for them for OpenCV 2.0. Thanks in advance.

+1  A: 

Since you're done compiling OpenCV, you need to create a new project in Visual C++

  1. Click File->New->Project.
  2. Select Win32 under Visual C++ on the left side
  3. Select Win32 Console Applicationon the right side
  4. Enter a name and click OK.
  5. Then click Finish.

Now, follow the instructions detailed in this tutorial to set the directories etc. It also has a sample program.

http://opencv.willowgarage.com/wiki/VisualC%2B%2B

Let me know if you have any difficulties.

Update: You need to put the folder containing the DLLs in the system path. You can find this folder in the same folder as the lib folder which contains cv200d.lib. Suppose cv200d.lib was in C:\OpenCV2.0\opencv\lib\debug then the Debug DLLs should be in C:\OpenCV2.0\opencv\bin\debug and the Release DLLs should be in C:\OpenCV2.0\opencv\bin\release. If you have any questions about adding folders to the path, let me know.

The above is mentioned in the tutorial you linked to:

4 Add the output directories to the system path, e.g.: C:\OpenCV2.0\vs2008\bin\Debug;C:\OpenCV2.0\vs2008\bin\Release:%PATH% It is safe to add both directories, since the Debug OpenCV DLLs have the "d" suffix, which the Release DLLs do not have.

Also, cv200d.lib would correctly configure the Debug mode of your project. You have to go to the Release mode of the project and add cv200.lib (i.e. without the d).

Jacob
I've already seen this tutorial. These instructions are for the older version of OpenCV because the folder structure for OpenCV 2.0 is different. The tutorial I was following, http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.0/OpenCV-2.0.0a-win32.Readme.Please.txt/download?use_mirror=ignum, is for OpenCV 2.0. I setup the global options and in page properties I added additional dependancies however, I noticed that instead of putting cv.lib I had to put cv200d.lib etc. After this I tried a program and it said cxcore200d.dll not founf on your computer.
Omar
Great job! So you've got the linker set up properly. Now you need to give your executable access to the DLLs - the simplest way to do this is put the folder containing those DLLs in the system path as an environmental variable - I've included this in my answer.
Jacob
@Jacob This must be a silly question but what does the :%PATH% mean in C:\OpenCV2.0\vs2008\bin\Release:%PATH%. When it says Add the output directories I went to create the folder but it was already there. Is there something additional I need to do.
Omar
When adding an environmental variable, does the variable name matter?
Omar
It means the output of the OpenCV solution you compiled. Once you've successfully built OpenCV, the DLLs and LIB files will be stored in the "output directories". The author of the document is just giving you a DOS-like way to set the path - essentially %PATH% means the old path so that the new path is the OpenCV directories + the old path. But you can set the system path through `My Computer` in Windows - do you know how to do that? If not, let me know which OS you're using.
Jacob
I'm using Windows 7. Isn't it System Properties>Advanced System Settings>Environmental Variables and then you add the variable? Does the name matter?
Omar
You don't need to **add** an environmental variable - you need to double-click `Path` in the `System Variables` section and add the paths of the output directories at the end. **DO NOT CHANGE THE OLD PATH IN ANY WAY**
Jacob
There was no path in the first place. I had to make one as I had seen in a previous tutorial.
Omar
Suppose the old path is `C:\Foo\Bar;C:\Bar\Foo`, you need to add a `;` and the OpenCV path, i.e. `C:\Foo\Bar;C:\Bar\Foo;C:\OpenCV2.0\vs2008\bin\Release;C:\OpenCV2.0\vs2008\bin\Debug`
Jacob
Ok, that's fine - you must be looking at the `User variables for Omar ...`, that'll work as well
Jacob
Well, does it work? If so you should really close out the other answers you've created :)
Jacob
I was just wondering...When i was installing OpenCV 2.0 I was given 3 options:1. Do not add OpenCV to the system PATH2. Add OpenCV to the system PATH for all users3. Add OpenCV to the system PATH for current userDoes this have anything to do with the problem. I chose option 1.
Omar
It hasn't worked yet but i'll close my other questions anyways. You've given me more assistance than I would imagine anyone giving me
Omar
No problem! Are you still getting the "DLL not found error"? Ok, try this: find the DLLs you need (they should be in that folder `bin\Debug` and copy them *into the Debug folder of your project`. Do the same for the `bin\Release` folder in OpenCV
Jacob
Look at my second last comment. Does this have anything to do with the problem. I'll try what you have said
Omar
It could be, if the above doesn't work, try reinstalling OpenCV with that option and recompiling.
Jacob
Finally, it works. I tried a helloworld app and it worked. I owe you a lot Jacob. Thanks for the extensive help.
Omar
Although it works. Is there a way to not have to copy and paste the .dlls every time I start a new project?
Omar
No problem Omar - one way to do that is to set the path. Maybe you should try appending the path of those directories containing the DLLs to the `Path` variable in the `System Variables` box and restarting Visual Studio.
Jacob
@Jacob Your advice worked! I added two system variables leading to the two sets of .dlls and it works without the copy and pasting. I think i'll make a video tutorial of how to install OpenCV 2.0.0a for Visual C++ 2008 Express Edition and upload it on youtube.
Omar
Haha, great idea, do post a link here so we can check it out later!
Jacob
Ok I will do so. By the way, thanks for your time and effort to help me.
Omar
A: 

Please have u created the video ? I'm still facing the same problem...

Mimo