1

I'm trying to run visual c++ with OpenCV. I have linked the OpenCV to Visual studio 2012. when I tried to run the code, it's giving me an error;

LINK : fatal error LNK1104: cannot open file 'opencv_calib2d246.dll'

Here's what I was trying to do:

#include "stdafx.h"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include<iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    if(argc !=2)
    {
        cout <<"usage: display_image ImageToLoadAndDisplay"<<endl;
        return -1;
    }

    Mat image;
    image=imread(argv[1],CV_LOAD_IMAGE_UNCHANGED);

    if(! image.data)
    {
        cout<<"couldn't open or find the image"<<endl;
        return -1;
    }

    namedWindow("Display Window",WINDOW_AUTOSIZE);
    imshow("Display Window",image);

    waitKey(0);
    return 0;
}

I have included all the libraries. I'm using OpenCV 2.4.6, on windows 7 32 bit system.

enter image description here

Anything more I have to add, or do I have to initialize it in the program?

Update

The path for OpenCV in my hard disk :E:\opencv\opencv. Path in the system environment variable: %OPENCV_DIR%\x86\vc11\bin;, where I have created a new variable as OPENCV_DIR and have given the path as E:\opencv\opencv\build. And in linker\command line

/OUT:"E:\VS2012 Projects\cvtest\Debug\cvtest.exe" /MANIFEST /NXCOMPAT /PDB:"E:\VS2012 Projects\cvtest\Debug\cvtest.pdb" /DYNAMICBASE "opencv_calib3d248.lib" "opencv_calib3d248d.lib" "opencv_contrib248.lib" "opencv_contrib248d.lib" "opencv_core248.lib" "opencv_core248d.lib" "opencv_features2d248.lib" "opencv_features2d248d.lib" "opencv_flann248.lib" "opencv_flann248d.lib" "opencv_gpu248.lib" "opencv_gpu248d.lib" "opencv_highgui248.lib" "opencv_highgui248d.lib" "opencv_imgproc248.lib" "opencv_imgproc248d.lib" "opencv_legacy248.lib" "opencv_legacy248d.lib" "opencv_ml248.lib" "opencv_ml248d.lib" "opencv_nonfree248.lib" "opencv_nonfree248d.lib" "opencv_objdetect248.lib" "opencv_objdetect248d.lib" "opencv_ocl248.lib" "opencv_ocl248d.lib" "opencv_photo248.lib" "opencv_photo248d.lib" "opencv_stitching248.lib" "opencv_stitching248d.lib" "opencv_superres248.lib" "opencv_superres248d.lib" "opencv_ts248.lib" "opencv_ts248d.lib" "opencv_video248.lib" "opencv_video248d.lib" "opencv_videostab248.lib" "opencv_videostab248d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"E:\VS2012 Projects\cvtest\Debug\cvtest.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\cvtest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1

Now I'm not able to load image. No fatal errors and nothing. It is considering the if statement and not loading anything.

Any suggestions?

varsha_holla
  • 852
  • 7
  • 23
  • 41
  • did you add reference to this dll? i tried using opencv in c# i just added it in the reference – Anonymous Duck Sep 04 '15 at 06:56
  • go to linker/general and add the path where that .lib file is located to "additonal linker directories" or similar – Micka Sep 04 '15 at 07:10
  • @Micka I have checked the path. I have specified the path as well. Still I'm getting the same error. – varsha_holla Sep 04 '15 at 07:13
  • @EuphoriaGrogi I haven't tried it by adding the reference. I will check that out. – varsha_holla Sep 04 '15 at 07:17
  • can you post your linker command line (linker/command line) please and please post your openCV library path on your hard disk – Micka Sep 04 '15 at 07:43
  • @Micka I have updated my question. What I have to give in command line? – varsha_holla Sep 04 '15 at 09:29
  • in your configuration window, there is "Configuration properties" -> "Linker" -> "Command Line" which gives you a window with some textfield. copy and paste the whole text to add it to your question. – Micka Sep 04 '15 at 09:41
  • In your linker -> additional link directories add `%OPENCV_DIR%\x86\vc11\lib;` the BIN directory only includes the binaries (.dll), not the libraries! But you need the libs for linking. – Micka Sep 04 '15 at 09:42
  • @Micka I'm using Visual studio 2012 professional and opencv 2.4.6 which contains vc9,vc10 and vc11. Will it cause any problems? – varsha_holla Sep 04 '15 at 13:31
  • 1
    either add : %OPENCV_DIR%\x86\vc11\lib; to system PATH environmental variable or add it to "additional library directories" in linker->general – Micka Sep 05 '15 at 10:23

1 Answers1

2

You need to set up more than just your linker dependencies and it is very likely you have missed a step.

I would suggest following this tutorial as it will get you setup completely.

Community
  • 1
  • 1
GPPK
  • 6,546
  • 4
  • 32
  • 57