views:

2747

answers:

8

I am trying just a basic program with OpenCV with the following code:

#include "cv.h"
#include "highgui.h"

int main()
{
    IplImage* newImg;
    newImg = cvLoadImage("~/apple.bmp", 1);
    cvNamedWindow("Window", 1);
    cvShowImage("Window", newImg);
    cvWaitKey(0);
    cvDestroyWindow("Window");
    cvReleaseImage(&newImg);
    return 0;
}

When I run this, I get

The program can't start because libcxcore200.dll is missing from your computer. Try reinstalling the program to fix this problem.

However, I can see this DLL. It exists. I have added the following to the input dependencies for my linker

C:\OpenCV2.0\lib\libcv200.dll.a C:\OpenCV2.0\lib\libcvaux200.dll.a C:\OpenCV2.0\lib\libcxcore200.dll.a C:\OpenCV2.0\lib\libhighgui200.dll.a

What gives? I'm using visual studio 2008.

When I link the .dll files instead of .dll.a files, I get

fatal error LNK1107:invalid or corrupt file: cannot read at 0x3F8 libcv200.dll

A: 

How did you get file names ending in .a ? This is non-standard for windows/visual studio and is probably the cause of your problem. Do you have a custom make file that has these names in them ? Did you download a bad versions ?

In OpenCV2.1 - do you have the following files ?

2085888   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\cv210.dll
3890688   4-05-2010   8:11p ----A  c:\OpenCV2.1\bin\cv210d.dll
1069568   4-05-2010   8:06p ----A  c:\OpenCV2.1\bin\cvaux210.dll
2437632   4-05-2010   8:13p ----A  c:\OpenCV2.1\bin\cvaux210d.dll
 940544   4-05-2010   8:08p ----A  c:\OpenCV2.1\bin\cvtest.exe
2201088   4-05-2010   8:04p ----A  c:\OpenCV2.1\bin\cxcore210.dll
3819520   4-05-2010   8:11p ----A  c:\OpenCV2.1\bin\cxcore210d.dll
 567808   4-05-2010   8:06p ----A  c:\OpenCV2.1\bin\cxcoretest.exe
 210944   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\cxts210.dll
 781312   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\highgui210.dll
1630720   4-05-2010   8:12p ----A  c:\OpenCV2.1\bin\highgui210d.dll
 407040   4-05-2010   8:04p ----A  c:\OpenCV2.1\bin\ml210.dll
 869376   4-05-2010   8:11p ----A  c:\OpenCV2.1\bin\ml210d.dll
 100352   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\mltest.exe
 128000   4-05-2010   8:08p ----A  c:\OpenCV2.1\bin\opencv_createsamples.exe
4668416   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\opencv_ffmpeg210.dll
5929984   4-05-2010   8:12p ----A  c:\OpenCV2.1\bin\opencv_ffmpeg210d.dll
 129024   4-05-2010   8:06p ----A  c:\OpenCV2.1\bin\opencv_haartraining.exe
  13312   4-05-2010   8:05p ----A  c:\OpenCV2.1\bin\opencv_performance.exe
 157184   4-05-2010   8:08p ----A  c:\OpenCV2.1\bin\opencv_traincascade.exe
Romain Hippeau
I'd seen this referenced on other websites with people troubleshooting a problem I had earlier and sure enough, these files are in the lib folder. Seems kind of strange, I agree, but I'm not the only one with these files
charles-22
@charles-22 in many moons of doing windows coding I have never seen a .dll.a file. In Unix/Linux that is typically the ending for a static library. Where did you get these files from ? Are there any that just end in .dll ?
Romain Hippeau
I got the files from sourceforge. There is a .exe for opencv that installed the folder and those are what are in the lib folder. There are .lib files though, I will try those
charles-22
This yields "fatal error LNK1107: invalid or corrupt file: cannot read at 0x3F8" for libcv200.dll. hmm
charles-22
Which file did you download ? - exact name and from where ? Did you follow the install in the readme ?
Romain Hippeau
http://sourceforge.net/projects/opencvlibrary/ the file is OpenCV-2.0.0a-win32.exe Yes, I followed the readme. Quite strange..
charles-22
@charles-22 do you have the same file as in the answer ?NOTE: I GOT VERSION 2.1
Romain Hippeau
No, I do not. In bin I only have the following dlls. libcv200, libcvaux200, libcxcore200, libcxts200, libhighgui200, libml200, libopencv_ffmpeg200
charles-22
It looks like you got the Unix/Linux version. Can you use 2.1 ?
Romain Hippeau
Interesting. I'll redownload and try that out.
charles-22
These are giving me identical errors to earlier, but I have all the same files that you seem to have.
charles-22
Remember the installation changed your path. can you check it ?
Romain Hippeau
I think we are going beyond the spirit of this web site. You do not have a programming issue, you really have a configuration issue with your basic package.You did have the linux version installed on windows. You now have the proper version. Can you run the IVP and make sure it is running properly. There are some test exes in the bin folde run one and see what it does. Also did you get rid of the old one ?
Romain Hippeau
A: 

Just add C:\OpenCV2.0\bin into your PATH environment variable

or

When you install OpenCV,

Choose the option, Add OpenCV to the system PATH for current user which is not default one

S.Mark
It's already in my path. I did notice this option when installing and I selected it.
charles-22
@charles, strange enough then, I couldn't reproduce your errors, your example codes running fine here. only I am using mingw32-gcc instead of visual studio 2008 c++ compiler.
S.Mark
Interesting. I really don't feel that this should be giving me this error, as it doesn't seem to be a common issue. Confusing.
charles-22
@charles, and I just tried both OpenCV 2.0 and 2.1, both are working, so not OpenCV version issue either.
S.Mark
Oh btw, @charles, your VC++ is 64bit? if so, it won't work.
S.Mark
Why would 64 bit not work? I'll have to double check
charles-22
@charles, its because of those .dll in `OpenCV2.0\bin` directory are compiled with 32 bit
S.Mark
I meant VC++ compiler, not VC++ IDE btw.
S.Mark
A: 

I just had this problem and found a great website. Basically, goto this website and follow the instructions on the .pdf. This ended up working great for me, so hope it helps you too!

http://nashruddin.com/OpenCV_2_0_Installation_on_Windows_XP_and_Visual_Studio_2008

Matt
A: 

The ".a" at the end of your DLL files is a problem, and those are there because you didn't use CMAKE to build OpenCV 2.0. Additionally you do not link to the DLL files, you link to the library files, and again, the reason you do not see the correct library files is because you didn't use CMAKE to build OpenCV 2.0. If you want to use OpenCV 2.0 you must build it for it to work correctly in Visual Studio. If you do not want to build it then I would suggest downgrading to OpenCV 1.1pre, it comes pre-built and is much more forgiving in Visual Studio.

Another option (and the one I would recommend) is to abandon OpenCV and go with EmguCV. I have been playing with OpenCV for about a year and things got much easier when I switched to EmguCV because EmguCV works with .NET, so you can use a language like C# that does not come with all the C++ baggage of pointers, header files, and memory allocation problem.

And as for the question of 64bit vs. 32bit, OpenCV does not officially support 64bit. To be on the safe side open your project properties and change the "Platform Target" under the "Build" tab from "Any CPU" to "X86". This should be done any time you do anything with OpenCV, even if you are using a wrapper like EmguCV.

typoknig
A: 

As to @Marc's answer, I don't think VC uses the path from the OS. Did you add the path to VC's library paths. I usually add the DLLs to the project and copy if newer on the build and that works very well for me.

kenny
A: 

just open the bin folder and copy and paste the .dll files to the folder you are working in..it should fix the problem

somebody
A: 

Copy all dll and .lib to your project directory. it will help you sur.

Mohamed boud
A: 

thanks mohamed and somebody it has worked copy paste the dll files into the bin folder of ur project if ur using emgu wrapper simple it workded for it'll surely work for u :) :)

ram6030