1

I've found several questions relating to this and have tried them. However, I am still unable to resolve the issue. Below are sites that I've used and an explanation of what I've done.

Visual Studieo 2010 with OpenCV 2.3.0

OpenCV Tutorial C++

Another Visual Studio 2010 example

What I am using are:

  • Windows 7 Professional x64
  • Visual Studio 2012 For Windows Desktop
  • OpenCV v2.4.10 extracted to D:\Development\OpenCV

Step 1: I went into Computer > Properties > Advanced system settings > Environment Variables and added: D:\Development\openCV\build\x64\vc11\bin\ at the end of the Path variable. And then I restarted the computer.

Step 2: Created a new project and edited the Properties for All Configurations.

  • Under Configuration Properties > C/C++ > General, I added D:\Development\openCV\build\include
  • Under Configuration Properties > Linker > General, I added D:\Development\openCV\build\x64\vc11\lib
  • Under Configuration Properties > Linker > Input, I added opencv_calib3d2410d.lib opencv_contrib2410d.lib opencv_core2410d.lib opencv_features2d2410d.lib opencv_flann2410d.lib opencv_gpu2410d.lib opencv_highgui2410d.lib opencv_imgproc2410d.lib opencv_legacy2410d.lib opencv_ml2410d.lib opencv_nonfree2410d.lib opencv_objdetect2410d.lib opencv_photo2410d.lib opencv_stitching2410d.lib opencv_superres2410d.lib opencv_ts2410d.lib opencv_video2410d.lib opencv_videostab2410d.lib
  • Under Configuration Properties > Linker > Advanced, I changed the Target Machine to MachineX64.

Step 3: For Build > Configuration Manager, the project is changed to x64 platform.

Step 4: I copied and pasted the code from one of the links above with the path of the image modified and built it.

#include "stdafx.h"

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("D:/lena.png");
    if (im.empty()) 
    {
    cout << "Cannot load image!" << endl;
    return -1;
    }
    imshow("Image", im);
    waitKey(0);
}

Step 5: I pressed F7 and the solution built successfully. (Sadly, took a while to just get to this point)

Problem is when I press F5, I would get an error saying "The program can't start because opencv_core2410d.dll is missing from your computer. Try reinstalling the program to fix this problem."

I thought the first step of adding it to the path is the solution. By moving the DLL into the D:\Development\VisualStudio\opencvHelloWorld\x64\Debug folder, I can run the executable. Can anyone shed light on how to fix this problem? What am I missing?

Thank you!

Community
  • 1
  • 1
Victor
  • 65
  • 1
  • 1
  • 6

3 Answers3

4

OpenCV needs any dll you are using for your project to be in the same directory as your executable. You can either copy the dlls you need, in this case opencv_core2410d.dll into your debug folder and opencvcore2410.dll into your release folder, or set visual studio to move your executable to the bin folder. This option is under Project->Properties, and on the General page you can change the output directory.

Another option is to use static libraries instead of dynamic libraries for opencv. This will add any opencv functions you are using right into your executable instead of using seperate dlls. This will make your executable much bigger, but will eliminate any dll issues. In the opencv directory, under build/x64 or x86/vc11, use the libraries in the staticlib folder to build the project as a static project. You will need to add a few more resources in your solution for it to compile at first. This answer should help with any linker issues you get by switching to a static build.

If you plan on deploying your executable and you don't want to package up dlls with it, using static libraries is another way you can go about your project

Community
  • 1
  • 1
Connor H
  • 346
  • 5
  • 16
  • Can you explain to me the point of adding the \bin to the path variable in the Environment Variable? Thanks. – Victor Nov 18 '14 at 01:46
3

Just restart Visual Studio AFTER you add bin to your PATH.

Kay
  • 63
  • 6
0

Please add the following under Configuration Properties > C/C++ > General,

1. D:\Development\openCV\build\include

2. D:\Development\openCV\build\opencv

3. D:\Development\openCV\build\opencv2

This will fix your problem.

Abc
  • 824
  • 2
  • 7
  • 20