1

I'm trying to install OpenCV 2.4.8. Turns out this is far more complicated as expected. The tutorials are all outdated. Here is my current problem:

I'm running on a 64 bit machine, and am trying just a simple sample code:

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace cv;


int main() {
    Mat image;

    VideoCapture cap;
    cap.open(0);

    namedWindow("window",1);

    while(true) {

        cap >> image;

        imshow("window", image);

        waitKey(33);
    }


    return 0;
}

When I run this, I get an error stating that opencv_core248d.dll is missing. Checking the bin directory, it's there. How do I fix this?

Regards

Edit: I've been on this issue for the past 3 hours. Whoever can help me solve this issue will get so much rep and love from me...seriously I'm getting desperate

Edit2: Picture of some settings:

OPENCV_BUILD = C:\OpenCV\build\

Settings1

Settings2

spurra
  • 1,007
  • 2
  • 13
  • 38

2 Answers2

2

You are running into OpenCV dll issues, similar to here. Three ways to fix dll-related issues about OpenCV, also works for other dll related issues.

  1. copy the required dlls into the same folder with your application. This is a little better because it kind of prepares you for when you'll need to deploy your application on systems that don't have OpenCV installed (for then don't forget to build the release version of your application).

  2. add the dll path to Debugging Environment: Project –> Properties –> Configuration Properties –> Debugging –> Environment –> add dlls' paths here. The syntax is NAME=VALUE and macros can be used (for example, $(OutDir)).

    • For example, to prepend C:\Windows\Temp to the PATH: PATH=C:\WINDOWS\Temp;%PATH%

    • Similarly, to append $(SolutionDir)\DLLS to the PATH: PATH=%PATH%;$(SolutionDir)\DLLS

  3. add the dll path to Environment Variables (be careful that the path in there are separated by ;)


EDIT: Among the three methods, the first two will only work for this project (local) and the last one works for all projects in your PC (global).

Community
  • 1
  • 1
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • 1. Which folder exactly? The project folder or a more specific subfolder? Adding it to the project folder changes nothing. 3. I've done that before. I still have that error. 2. I don't quite understand the syntax. But seeing that your other two solutions didn't work, I assume there's something "deeper" wrong with my program. – spurra Feb 27 '14 at 17:16
  • @BananaCode The output folder (where .exe is expected to generate). – herohuyongtao Feb 27 '14 at 17:34
  • This solution works. Thanks! However, it seems more like a band aid fix. Is there a way to circumvent having to copy each .dll file it needs? – spurra Feb 27 '14 at 17:40
1

Have you tried adding C:\OpenCV2.0\bin to your PATH variables? Yup, installing OpenCV can be a chore :/

Have you done the proper project setup, like adding source library, source directories etc? Anyway, if my guess if right, the following will resolve that particular error:

Go to your project properties, Linker -> Input -> Additional Dependencies, add opencv_core248d.dll in and compile. If a new error appears, means you have yet to do the proper configurations.

EDIT: to comments enter image description here

Here, the include directories and library directories. Did you add the relevant build/include & \lib into to the include and library directory respectively? This are some of the "configuration" that need to be done.

EDIT2: TO answer your edit

Yup, looks like you did do the configurations. Was confused by your comments.

1) I am not really sure if $(OPENCV_BUILD) will work. Maybe you would like to try C:\OpenCV2.4\lib, (link directly) etc instead of that.

2)Go to your linker input and edit the additional dependencies to this (image from one of the books I have):

enter image description here

Hope it works. And don't worry. I know how you feel. I was stuck at installing OpenCV for almost a week, and only one guy's youtube video saved me. I needed to edit some header files. But it's a different problem from yours. Good luck and hope my method work.

EDIT3: Hopefully this solve your problem, try these.

1) If you are using the "band-aid" method, which means having to copy paste the dll files every time, my suspicion would be that your PATH variables is wrong. Just double check it.

the equivalent for yours would be something like(the path of where you copied the dll files from/the path of the library directories you added inside the property page. But instead of lib at the end, you use the bin folder):

C:\OpenCV2.3\build\x86\vc10\bin

More details on this : Setting window path

If you have done this, just check that you have separated them with a semi-colon.

2) Not sure if this is really the solution for missing .dll file, if I remember correctly, it's more for linking errors. But give it a shot if step 1 doesn't work, or if step one works and you face another error. At the most, you can just undo it.

For each header files, for instance the core.hpp file, add the following lines:

#pragma comment(lib,"opencv_core248.lib")
#pragma comment(lib,"opencv_core248d.lib")

This need to be done for all the header files you use. Where to place it? I place mine here: enter image description here

This goes the same for highgui.hpp, etc, but you change the name, so #pragma comment(lib,"opencv_core248.lib") becomes #pragma comment(lib,"opencv_highgui248.lib", etc...

Hope all goes well. I think if the path variable, but if not and 2nd method doesn't work, I have no clues anymore.

rockinfresh
  • 2,068
  • 4
  • 28
  • 46
  • I'm using version 2.4.8. That path does not exist. But I've put the equivalent of it into the path variable and I get the same error. I have not done anything to the VC++ Directories option, as none of the tutorials I used stated anything about them. – spurra Feb 27 '14 at 17:19
  • Have you tried my Linker -> Input -> Additional Dependencies solution? Did a new error appear? – rockinfresh Feb 27 '14 at 17:24
  • Yup, there are many different tutorials out there, most of them actually ask us to do the properties... Which tutorial did you use? I shall edit my answer to show you the VC++ Directories option in my own VS 2010 – rockinfresh Feb 27 '14 at 17:27
  • Yes, I've tried the Additional Dependencies solution, did not work. Thanks for your help, really appreciate it. – spurra Feb 27 '14 at 17:28
  • @BananaCode, which tutorial did you use? Since you mentioned the VC++ directories, I show you mine(Zoom in if its not that visible). As u can see, it is edited. In fact most books, or sites, etc will ask us to do such configurations in the introduction section. – rockinfresh Feb 27 '14 at 17:32
  • Tried that. Didn't work. I was following the tutorial here: http://www.youtube.com/watch?v=cgo0UitHfp8. And the "official" visual studios tutorial from the openCV main website. I've added pictures of some of my configurations. – spurra Feb 27 '14 at 17:38
  • @BananaCode: Edited my answer to reply to your edit. Hope it works. – rockinfresh Feb 27 '14 at 18:03
  • Relax, OpenCV is not exactly user friendly in terms of installing. I help you to upvote the question. Bit busy now, I try think of more reason what could be wrong tomorrow. – rockinfresh Feb 27 '14 at 18:38
  • Thanks. In the mean time, I applied a band aid fix by copy-pasting all the libraries into the folder where the .exe resides, as suggested below. – spurra Feb 27 '14 at 21:16
  • Do upvote again if you find it useful, the vote for this answer was removed due to a "serial upvoting script". More details of that here: http://meta.stackexchange.com/questions/126829/what-is-serial-voting-and-how-does-it-affect-me. Haha. Cheers! Do let me know if it works anyway(: – rockinfresh Feb 28 '14 at 03:57
  • Oh sorry about that. That was me, trying to compensate for your efforts. Hope I didn't cause you any trouble :( Anyways, the solution sadly didn't work. Neither of them. There must be something wrong with my understanding or the system. I'll see if I can get help at the university. Thanks again for your help, appreciate it. – spurra Feb 28 '14 at 09:37
  • Nope. It didn't. Dont worry. You can upvote other answers of a user, but if its too many, the script will detect if its from the same user. – rockinfresh Feb 28 '14 at 13:05
  • 1
    Sorry. If it's face to face, probably can help you more. Hope you get it right. Don't give up. OpenCV installation is a chore. But the library is very fun and useful! The problems after that will be minimal if you have decent programming skills. (: Do let us know the solution if you do get it. I ask around for u too. If I have a new solution, will edit my answer again (: – rockinfresh Feb 28 '14 at 13:07
  • Hey mate, I solved the issue. Turns out, CUDA somehow messed up my libraries. I simply recompiled everything on an other computer with freshly downloaded source files and CUDA installation, and it all works well. I'll accept your answer, enjoy some more rep :) – spurra Mar 11 '14 at 17:44
  • Thanks and nice to hear that you solved it (: Its always these small issues that are hard to spot:/ – rockinfresh Mar 13 '14 at 02:05