A blog about anything a software engineer might encounter during his programming efforts.

11 July 2012

Installation guide: OpenCV 2.4 with Visual Studio C++ 2010

After some trouble installing OpenCV 2.4 in Windows and using it with Visual C++ 2010, I decided to write a post about this, so I can hopefully save you some time figuring this one out. It is based on this wiki, but that describes how to build with CMake etc, which is not necessary (anymore?).

Okay, so first you need to download OpenCV 2.4 here. After downloading, you need to extract it. I have extracted it to "D:\OpenCV2.4.2\" and I will use this folder for the rest of this post, you can change it if you like.

Edit your PATH variable (right click on this computer, properties, then select the tab "advanced" and click on "Environment Variables", which is near the bottom).

Add these paths to your Path Variable:

D:\OpenCV2.4.2\opencv\build\x86\vc10\bin

D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10

Replace the beginning with your install path of course. It think that you would need to replace x86 in the first path with x64 and ia32 in the second path with intel64 if you want to build a 64 bit application, although I am not sure about this.

Now we are ready to create a project with OpenCV. In Visual C++ 2010, create a new Win32 console application called OpenCVTest. Now right click the project and select Properties.

On the left, choose C/C++ and edit the Additional Include Directories. Add these directories:

D:\OpenCV2.4.2\opencv\build\include\opencv

D:\OpenCV2.4.2\opencv\build\include

Now choose Linker and add this directory to the Additional Library Directories:

D:\OpenCV2.4.2\opencv\build\x86\vc10\lib

Again I think you need to replace x86 with x64 if you want to build a 64 bit application.

Now open the Linker group (press the + sign before it) and select Input. Add these lines to the Additional Dependencies:

opencv_core242d.lib

opencv_imgproc242d.lib

opencv_highgui242d.lib

opencv_ml242d.lib

opencv_video242d.lib

opencv_features2d242d.lib

opencv_calib3d242d.lib

opencv_objdetect242d.lib

opencv_contrib242d.lib

opencv_legacy242d.lib

opencv_flann242d.lib

Replace 242 with your version if you're not using 2.4.2. Easiest is to paste these lines in notepad, press CTRL+H and set it to find "242" and replace with "251" (would your version be 2.5.1 for example).

And this one cost me a couple of days to figure out: if you do a release build, please remove all the d's in the above filenames (so opencv_core242d.lib becomes opencv_core242.lib), otherwise it won't run properly!

Finally you're ready to use OpenCV. To test it, paste the following code in your OpenCVTest.cpp file:

#include "stdafx.h"

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])

{

IplImage *img = cvLoadImage("D:\\funny.jpg");

cvNamedWindow("OpenCV",1);

cvShowImage("OpenCV",img);

cvWaitKey(0);

cvDestroyWindow("OpenCV ");

cvReleaseImage(&img);

return 0;

}

(Please replace D:\\funny.jpg with a valid path to an image! Also make sure that you use double backslashes in stead of one, this because the backslash is an escape character in C++.)

You do let it run to the cvWaitKey command? If you put a debug break on the ShowImage line, it won't actually draw the image until the cvWaitKey(0); is called. What happens if you replace it with cvWaitKey(); (without the 0)?

Hmm, I'm afraid I really don't know what could cause this. Have you tried loading another image? You could also try commenting the cvNamedWindow line, as it is not really necessary, cvShowImage should create a Window if it does not yet exist.

No, those are okay. PDB files contain the debug symbols, if they cannot be loaded, your debugger cannot point you to the correct line of code when something goes awry. In other words, when a bug in OpenCV would produce an exception, you wouldn't be able to see what line of OpenCV code caused the exception.

I'm afraid I have no experience with Cuda, but you can find a guide here:http://opencv.willowgarage.com/wiki/OpenCV_GPU

After you successfully build OpenCV, you can follow my guide, but make sure that the paths I use point to the paths in your own build. The first couple (that are added to the PATH variable) should point to directories with dll's in them. Additional Include Directories for the C/C++ compiler should point to directories with header files (.h and .hpp files) and the directory for the Linker should point to a directory with the library (.lib) files.

Ah, now I see the problem, but somehow I have looked over it: The path to the file should be like "D:\\image.jpg" (notice the double backslash). This because the backslash is an escape character, so you have to escape it to actually have it in the string variable.I have to admit the mistake was in my example code, I have overlooked this while altering the path to the image (because the path I had was longer and useless to others).

Thanks Anonymous for pointing me in the right direction. Using a slash in stead of a backslash would work too.

I am working with windows 7, 64-bit. And I should use VS2008. I did this step "Add these paths to your Path Variable:D:\OpenCV2.4.2\opencv\build\x86\vc10\binD:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10"

which I was not sure if was correct for win 64 bit.

I did all the steps. I opened an application in win32. and added all the paths to the program. But when I press F5 I get error which says "this project is out of date, would you like to build it?" If I press yes, I get another error which says: There were built errors. Would you like to continue and run the last successful build?

Have you tried creating a new project with the example code? It seems you have altered an existing project, which won't build. VC++ always asks if you would like to run the last successful build when a build fails.What does the error window say?

Also would you please explain the below part again. As I said before, I am using Windows 64 bit. I do not know what I need exactly do here. I just copied these two links and added them to the system path. ( at the end of the path)

Add these paths to your Path Variable:D:\OpenCV2.4.2\opencv\build\x86\vc10\binD:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10Replace the beginning with your install path of course. It think that you would need to replace x86 in the first path with x64 and ia32 in the second path with intel64 if you want to build a 64 bit application, although I am not sure about this.

Now choose Linker and add this directory to the Additional Library Directories:D:\OpenCV2.4.2\opencv\build\x86\vc10\libAgain I think you need to replace x86 with x64 if you want to build a 64 bit application.

You only need to use the 64 bit paths if you actually try to build a 64 bit application. Most probably you're building a 32 bit application, so you can just use the x86 paths. (It should say Win32 in your build configuration in VC++).

About the missing .exe: When VC++ can't properly build your project, it asks if you would like to run the last successful build. Because there was no successful build previously to this one, there is no .exe file, hence the message that it cannot find OpenCVTest.exe. This is "normal" behaviour for when a build fails.

Please take a look in your errors window (Somewhere in the View menu), they will give more information about what is wrong.

Please note: DLL files are loaded at runtime, so they cannot be the reason for a build failing. Any problems with DLL files will only surface when a build was successful and your application was actually started.

Try adding ", 1" after the image. What does your intellisense say? Does it need any extra parameters? You could also try the OpenCV 2.x C++ approach (see the last it of example code in the guide itself), maybe that works better?

Now there are 7 new errors, after adding one.Although, it said: ",int iscolor=1)" while I was typing.I also tried the cpp approach, and got a lot of errors.Do you think I should remove the openCV 2.4.0, and install the openCV 2.4.2?Thanks,Or.

These errors are produced by the Linker. Please check the settings under the Linker in the project properties. Do you link to the 32 or 64 bit libraries (*.lib files)? And did you add the additional dependencies correctly? If you are using version 2.4.0, I think these would be opencv_core240d.lib, rather than opencv_core242d.lib (notice that the version number is inside of the name of the file).

This means your compiler can't find the highgui.hpp file. You need to add the folder where it resides to the include folders of C/C++ in your project, see this part of the guide:On the left, choose C/C++ and edit the Additional Include Directories. Add these directories:D:\OpenCV2.4.2\opencv\build\include\opencvD:\OpenCV2.4.2\opencv\build\include

I deleted the space between the paths, and I run the program again. But I am still getting the same error. At first I get "this project is out of date, Would you like to build it?" and when I press yes, I get the above error.

Could you give it a try with highgui.h in stead of highgui.hpp? I don't have access to my code right now, but maybe I made a mistake and the highgui include should point to a .h file rather than a .hpp.

MSVCP100D.DLL is the debug runtime dll from VS2010.If you replace the Runtime Library with the non-debug version, you are basically running the app in release runtime. In this case, you need the other *.lib files (see my guide itself for this).BUT ... the important thing to notice, is that MSVCP100D.DLL belongs to VS 2010, not 2008. It's only now that it dawned on me ... you are using the VS2010 folder of OpenCV.

As you've probably noticed, all the paths I used (like D:\OpenCV2.4.2\opencv\build\x86\vc10\lib) have "vc10" in them, which means VS2010. Because you're using VS2008 (which is VC v. 9), you should have used the paths with "vc9" in them.

So basically what you need to do now:Go back to debug runtime, not release.Leave everything as it is, except the paths with "vc10" in them, replace it with "vc9" (please check if these folders exist!).And try a new debug run.

I know for a fact that it works with the Express Edition of Visual C++ 2010. From you earlier post, I also noticed that you are using a 32 bit build (win32), so you should use all the x86 paths.Also, you state that under Linker/inputs it states kernel32.lib;etc., but I don't see the additional includes that you can find in my guide. Did you add these? (like opencv_core242d.lib etc.)

OMG Thanksssssssssss it worked!!!!!! it showed the picture!!!!!Thank you Thank you so much!! :D*********************************I changed the system settings >> environment variable to:C:opencv\build\x86\vc9\binC:\opencv\build\common\tbb\ia32\vc9

I went to the paths above and I noticed both of them have vc8 folder too. Do I need to change them to vc8?

@Wisi: I'm sorry, I don't have Matlab now and I haven't tried getting OpenCV to work with it. But Matlab already has a lot of ways to work with images, seen as they are also just matrices. I know I have used Matlab once to write a program for gesture recognition and as far as I can remember I just used "plain" Matlab functions to do so.Good luck with your project!

I noticed that you are linking to the 64 bit versions of the libraries. Are you actually building a 64 bit app? You are probably doing a 32 bit build, even though you are working on a 64 bit computer. When you try to do a 32 bit build, the linker needs the 32 bit libraries too.Please check your build configuration in Visual Studio. Either set it to a 64 bit build and use the 64 bit libraries (and binaries), or have it on 32 bit (Win32) and use the 32 bit paths as used in this guide.

The first error is a result of the second; because it didn't build, there is no .exe to run.

About the second error: for some reason your Linker cannot find the .lib file(s). Please check both the path that you have set for the linker (Additional Library Directories) and the Additional Dependencies (the list of .lib files). One of these contains an error.It might also be that you are pointing to the wrong version, i.e. the 64 bit version, while you are building a Win32 application (you are actually building a 32 bit debug configuration by the way).

Not finding libgcc has nothing to do with OpenCV. This is a library that is needed when you used gcc (probably MinGW?) as compiler. You are probably not working with VC++, as that would have used the MSVC compiler.You are better off asking about this error on a forum related to that compiler or IDE.What you can do is search for this dll on your computer (it's probably where you installed your MinGW or other gcc compiler) and add the path to it to your system's path variable.

Hi Michael, I want to ask what is CMake and the tortoise SVN actually for in OpenCV project?And I also want to ask you, are you ever been doing project for detecting hand gesture and make it to become an order in windows, I want to make it become my university project.Thanks so much. Cheers :)

HI Elisa,Cmake is for building your own version of OpenCV from Source Code, but it's not needed when using the MSVC compiler (the one in VC++), because the OpenCV provide a build with that compiler in the build folder.Tortoise SVN is an SVN client, which you use to get out from and insert it into a sourcecode repository. You can Google for SVN.I have also wrote a program for hand recognition when I was at university, but that was with Matlab and very basic operations (OpenCV wasn't there yet, I think). I remember that we created a near-field IR camera (you can find tutorials how to turn a cheap webcam into an IR camera on the internet). Using that, we could more easily segmentate the hand.After you have a binary image of the hand (with 1 = hand, 0 = not hand), you can use temporal templates to recognise dynamic gestures and contours and other shape information for static gestures.Through Matlab, we have been able to use it for controlling a video driving game, but to be honest, I don't remember how we did that. All I remember was that you could wave your hands up and down for going slower and faster, left and right for going left and right and that "the finger" would trigger the horn :-D

Hi michael, could really use your help.I had no luck using the opencv tutorials but yours seem to be a lot easier to follow. The build was successful but right before starting displaying the image it will say "The application was unable to start correctly (0x000007b). Click Ok to close the application." Then it shows: new.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).'new.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).'new.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).The program '[8464] new.exe: Native' has exited with code -1073741701 (0xc000007b).

Hi, please check if the image was properly loaded through imread. Easiest way to do this is to check img.empty(). It wil return true if the image is empty.If so, check the path to the image and check if you are linking to the right libraries. You need the 32 bit libraries as you are creating a 32 bit build I think (Visual Studio itself is always 32 bit by the way).Also, please note that the libraries for a debug configuration end in *d.dll, the ones for a release build do not have this trailing d.

If the image is actually empty, you might want to check the path to the image file. Did you add the path to the path variable? Try restarting VC++ and/or your computer, it seems this is sometimes needed for the path change to get through.

Did you try the img.empty() trick? Is the image empty?Also, since it throws a cv::Exception, try catching it, like so:try{// do work here (like reading and showing img, etc.}catch(cv::Exception &ex){cout << ex.what();}

This will give you the contents of the exception. Most probably an assert error, stating that nr. of channels must be > 0 (which occurs because of passing an empty image to the show command).

Did you try stepping through your code? You can do so by placing a debug breakpoint on a line. When your debugger breaks there, you can step through your code a line at a time with F10 or resume execution with F5.

Hi Michael,For the image hand, should I do training or can I do something more simple than that? because actually I don't know how to do the image training to the application and it seems to be so hard.And I want to ask, what is the different between we create our project in Debug and Release. :)thanks

Like I said, look up on the internet how to make a cheap IR-camera out of a regulare webcam. Using that, you can find skin and the hands. What I did at university involved training, because you don't know the lighting conditions and other ambient lighting, which all influences the colours.

Debug vs Release basically differs in what it says; a debug build is a build that is made for debugging. This means that the debugger can find the line of code where something went wrong (it it did) and it enables you to use break points and stepping through your code step by step. A release build is a build meant for your release environment. Generally this code is optimised and quicker than the debug build (in terms of speed and memory usage). But, release builds are harder to debug, because some of your code might be shuffeled because of optimisations. Therefor, breaklines usually don't work, you can't step through your code step by step correctly (sometimes it works, but it's not reliable) and quite often your debugger doesn't know what line caused an exception if one occurs.

Thank you so much for this post! Spent 2 whole days trying to get OpenCV to work and finally your tutorial helped.. I was being an idiot and setting the libraries to use the 64bit ones because I have a 64bit machine, but I didn't realise that its for when you are making a 64bit program! Silly me!

My question is, do we have to keep repeating this procedure for every new project that we create in VS2010 in order to run OpenCV in it? Isn't there any way to be able to run OpenCV in every new project? Or a shortcut to activate running of OpenCV in a new project?

I tried running the same code that I used in the Test project where I configured OpenCV, in a new project. I included the line " #include "stdafx.h" ", after which I wrote my code. It didn't work. Couldn't figure out even header files like cv.h, highgui.h

Good to hear it worked for you. I think it is possible to add these settings more easily, using property sheets. The problem is that these only work in the paid version of Visual Studio and I only have access to the Express edition.

Thank you very much it is a really help full article. I am new in C so I have two questions maybe they are very basic1- It works when i debug and when i try to release the project it does not work. 2- What is a difference when we try to install the OpenCV through the CMake and by following your article? Is only compilation difference?

1. See this remark: "... if you do a release build, please remove all the d's in the above filenames (so opencv_core242d.lib becomes opencv_core242.lib), otherwise it won't run properly!"2. The only difference is that my guide uses prebuilt libraries, i.e. libraries that the OpenCV crew has already built for you (most probably using CMake and the MSVC compiler).

Thanks so much for your post, Michael. I spent whole 3 day to get opencv with MSVS, searched on internet, read very much guide, finally i found your post. It helped me. So i spent a hour to read all questions and your answers. It gives me more experience.

After spending two days trying to get OpenCV working using various instructions across the web, this was the procedure I ended up using and it worked. Great write up! One weird thing I had to do was restart Visual Studio before it would catch changes I made to my PATH.

THANKS A LOOOOT DUDE!! YOU SAVED MY LIFE!! JEJE... JUST ONE QUESTION... WITH THE PROCEDURE THAT WE'VE DONE HERE, AM I ABLE TO USE THE OPENNI LIBRARIES RIGHT NOW? I MEAN, DO I HAVE TO "TURN THE LIBRARIES (OPENNI) ON" BY MEANS OF CMAKE? OR, DO WE HAVE IT ALREADY CONFIGURED? :) THANKS A LOT AGAIN!

I think there are various guides for that on the internet. I don't think you can do that without building the sources yourself (usually this is just these steps: "./configure", "make" and "make install").It all depends on what development tool you are using. If you plan on using a graphical IDE, I'd suggest Qt Creator, it's a solid IDE and provides access to all Qt functionality, which makes programming a lot easier and you can write cross-platform code more easily.

To enable OpenNI, I'm afraid you'll have to make your own build. It's not that hard and there are guides on the OpenCV sites. Just install CMake, run its GUI and point it to the OpenCV directory. There you can configure it. To enable OpenNI, you need the OpenNI libraries on your system, and you can enable it by setting the option to TRUE in CMake.After you're done with CMake, you can build OpenCV with Visual Studio and you will have your own build, with OpenNI support.

Glad to hear my guide helped you. As for adding the settings for eacht project: All I have been able to find was the use of so-called property sheets. They do not seem to be available in the Express Edition of Visual Studio, so I haven't been able to try them out. If you do have a paid version of VS, you could do a search on these and you'll probably be able to use them for this. If you too use the Express edition, I'm afraid you'll have to keep adding them manually.

Hi. I'd like to thank for this tutorial. Almost everything works except getting video from my notebook's camera. I'm sure that camera works because I use it for wideoconferences in skype. I compiled following program:****************************************#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"

while (cvWaitKey(4) == -1) { cap >> frame; imshow(window, frame); } return 0;}****************************************Program seems to work properly because there is no errors but instead of video I see green picture. I would appreciate if you could help.

Hi, i got a problem this is my code, it build successfully, but right before starting displaying the image it will say "The application was unable to start correctly (0x000007b). i dont know what to doand i am a beginner C++

Sorry, I don't know that device. I think you'll have to find out how to compile code for it (and how to deploy it). You'll most probably (unless it supports an x86 instruction set) have to build your own OpenCV binaries for it too.First try to compile some simple code for it and get it too run, don't try to do it all at once.

Not all cameras agree with the way highgui accesses them. Maybe your camera is one of these.Just to check if your OpenCV is in order: did you try the example code, loading an image from disk and displaying it? Did that work as expected?

Did you add the path to the DLL's to your system's PATH variable? Sometimes you need to quit and restart Visual Studio before it sees these changes.Are you building a 32 or 64 bit application? Are you including the right directories for it? (Don't use the 64 bit paths just because you're on a 64 bit computer, usually you're still building 32 bit applications).

Generally after configuring OpenCV in way you showed here I was able to load images and play films (.avi), but not using code you wrote because I cannot include "stdafx.h". How to fix it? Download it and paste from internet...?And I'd like to ask about my camera if it is possible to make it work? It works while program is opened (LED is indicating it)PS. I wanted to write in previous post that I see grey image instead of green but I think it isn't so important:)

You can remove the include for stdafx.h if you don't have that file in your solution, it is used (and automatically created) when Visual Studio is configured to use pre-compiled headers.If you are able to play films and display images, your OpenCV is configured properly. If your camera doesn't produce any image, I'm afraid your camera is not compatible.You could try cap.read(frame); in stead of cap >> frame, it is what I always use. Little chance it makes any difference, but you might as well give it a try.

If not, you could try searching for your specific type of camera and its use in OpenCV, maybe Google can find some information on whether the camera has been used successfully or not.

I followed your guide and built the code you specified. All worked well until I got an error saying 'This program cannot start because opencv_core 242d.dll is missing from your computer'. I checked and it is there in my bin file! Would you be able to help me with this problem?

Hi Conor,This usually happens for one of these reasons:1. The path with the DLL is not in your system's PATH variable (see the beginning of my guide).2. Visual Studio didn't notice you changing your PATH variable. Try restarting Visual Studio or your computer.

Missing PDB files is just indicating that there is no debug information for these dll's (which is normal). You can ignore these warnings. You might want to look up the error code, or try stepping through your code line per line, to see whre the problem occurs.

It can't find the correct *.lib files. Check the steps that have to do with the Linker. Make sure you use the *d.lib files for your debug configuration and the *.lib (without the extra d) for your release configuration.

Did you add "D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10" to your system PATH variable? If you did, try restarting Visual Studio or your whole computer, sometimes they need a restart before the PATH variable is updated.

Can you find the tbb_debug.dll file? The PDB errors can be ignored, that just means there's no debug information for the dll files, but that's correct.

If you can find the tbb_debug.dll, you might try copying it to the directory where your .exe is placed and running it. If this works, it means the file is okay and that the problem is that it cannot be found in any f the system paths.

hi micheal..i'm facing this problem...the program can't start because opencv_core242d.dll is missing from your computer. try reinstalling the program to fix the problem.what should i do?i'm using win7 64bit and VS2010 32bit

Sorry to hear you're having so much troubles. Cannot open a header (.h or .hpp) file means your include directories are not set correctly. See this step: On the left, choose C/C++ and edit the Additional Include Directories. Add these directories: D:\OpenCV2.4.2\opencv\build\include\opencv D:\OpenCV2.4.2\opencv\build\includeOn the left of the project settings window that is.

Thank you! I have struggled with other tutorial's but was able to get it to work with yours. I had a few snags in there, I changed the path to have / instead of the \\. I also had to restart VS to get everything to work.

Finally i handle it . i have opened a image :) i am so happy thanks to you. i handle it in 2012 also.if you have had problems like me i just added to windows path all the possible directirios in opencv2.4.2. They are

I am trying to install OpenCv 2.4.2 on visual studio 2008 with Cuda. I downloaded the OpenCv from the official website, downloaded Cmake. Configured the OpenCv with Cmake. Changed the path variables. And then when i try to build the solution it fails. Below is the error. Please help.

That's the linker complaining it cannot find the .lib files. See the steps concerning the linker in the guide. Please note that you need the files with the "d" suffix for debug builds and the files without that "d" for release builds.

Please follow the steps concerning the Linker in the guide. These "external" symbols should be found in the *.lib files. Take care to use the correct ones, those ending with a d for your debug build and those without the d for your release build.By the way, why are you using a beta version of opencv, when you can get version 2.4.2 from the site?

I have linked the path containing all the .lib files in the project->properties. Did try restarting the computer. Really confused with this error.Versions i use: it is a 64 bit Windows 7 OSOpenCv: 2.4.2Visual Studio: 2008 and 2010(tried with both)Cuda: 4.2 and 4.1Cmake: 2.8.9Graphics card: NVIDIA Geforce GTX 550 Ti

First of all I have to admit I have never built a Cuda enabled version, but I have build custom versions using CMake. Did you use the CMake GUI to configure it? All I know is you tell CMake to create a folder with all the stuff you need to build a version using Visual Studio and it creates a .sln file that you can just open and build with Visual Studio. Even without doing anything in Visual Studio itself, the .sln should just work.

What I assume is that you have more errors before this fatal one. Since you are building your own version, you are also building your own .lib and .dll files. Not finding the .lib file in the debug folder woud mean that building this lib file failed. Try finding why in the error log.

Hi, I am using windows 7 with 32-bit OS and i have installed opencv 2.4.2 with vs 2010 and when I the the code above by following instructions with it gives me this error:the program cannot start because opencv_core242.dll is missing from my computer although I have the complete file of opencv if I see the size.Thanks

Hicould you please let me know how to change linker configurations(u asked to include few libraries in linker) in DevC++ new version.or the procedure perhaps .. .i included the c++ includes, code complies fine . .but lots of linking error

I 'm using Win64 with VS 2010 and I'm trying to do a project vith openCV 2.4.2. but I always have the same problem (added at the end).

I also tried to do your simply test to open an image, and with opencv 2.2 it hasn't been any problem but with 2.4, version what I need to my project, the project doesn't work. And also when I build the program it erase me the .exe!!!

'test2.exe': Loaded 'D:\UPC\Projecte\work\OpenCV_242\test2\Debug\test2.exe', Binary was not built with debug information.'test2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Program Files (x86)\ThreatFire\TFWAH.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file'test2.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Cannot find or open the PDB fileThe program '[1812] test2.exe: Native' has exited with code 0 (0x0).

Those PDB file warnings can be ignored. They just inform you that you have no debug information for those (Windows Native) dll files.Deletion of the .exe is fairly normal too: When building, first all target files are deleted, so they can be built again. If building fails, the original .exe will be gone.

What IS weird though, is that building seems to go fine, but the problems arise during runtime, which should NOT result in the .exe disappearing.

What catches my eye though, is that it states that the .exe has no debug information. Please check your build configuration, it seems you are building a optimised (release) version in your debug config?

Even if you choose your configuration that is called "Debug", you can set it to produce no debug information. Even so, it remains strange that your .exe has no debug information.

You can copy the dll's to the debug folder, but if you have set the PATH variable, that wouldn't make any difference.

Are you sure these are the only warnings/errors you get? These indicate that building was successful, as they are only warnings and even state that the process has exited. (And if it can exit, it was built!)

These make a lot more sense. Again, deleting the .exe is normal operation, it needs to delete the old build, to make room for the new one. If the new build fails, you end up with no .exe at all.

There are basically 2 problems:1: There is an 's' in line 15 of your test2.cpp that makes no sense.2: Your linker cannot find the *.lib files. Make sure you have entered both the path and lib files as explained in the guide. Also make sure that you use the files with the 'd' at the end of the name for your debug configuration.

And about the 's' in line 15: You probably have a path there, that contains backslashes (\). Replace them with double backslashes.Since the backslash is an escape character, it has special meaning. '\\' means '\'. '\n' for instance, is a newline character. '\s' cannot be parsed and would produce an error such as the one you're getting.

You can also replace the backslash with a forward slash (/), which is more widely used too, the backslash is only used in Windows.

---------Now choose Linker and add this directory to the Additional Library Directories:D:\OpenCV2.4.2\opencv\build\x86\vc10\libAgain I think you need to replace x86 with x64 if you want to build a 64 bit application.---------

By the way, you are most probably building 32 bit application, so use the 32 bit paths. You're only building a 64 bit app if you target platform is set to 64 bit.

This might happen if you're still running the exe file. Sometimes Visual Studio keeps a lock on it. Best way to solve that is to close Visual Studio and delete the file by hand. After that, you can restart Visual Studio.

This has nothing to do with the "crt no warning", since the others were errors, not warnings. Since this is the first step in buiding the .exe, it fails immediately, before the other errors occur if it cannot delete the file.

HiWhen I remove those d's from the lib files, and press F5 to run the project I got this error "The procedure entry point ??task_group_context@tbb@QAE@XZ could not be located in the dynamic link library tbb.dll".But when I add d's to those lib file it is OK and works perfect.I am using VS 2008.Could you please tell me whats the problem?

Did you also change your build configuration to release? If you use the release libraries (without the d's) for a debug build or vice versa, you'll get weird problems.

In Visual Studio, you can setup different settings for the release and debug build. That way, you can make the debug configuration include the debug static libraries and the release build include the release static libraries.

I followed your tutorial as it is and used the 2nd code snippet given by you. I am running Windows 7 64-bit, Visual Studio 2012 and am building the project in Release mode. I have linked the appropriate libraries too (removing the d's from opencv_core242d.lib, etc.). The program Builds fine. However when I try to Run it, I get an error like this:

"The application was unable to start correctly(0xc000007b). Click OK to close the application"

Please check your PATH variable. If it is correct, try restarting Visual Studio or your computer. The error here is that the dll files are in these directories and cannot be found.The warnings about the missing PDB files can be discarded, they just say you have no debug information for the mentioned dll's, but that is normal.

Does it give any other information why the application could not start correctly? Is it missing some dll files for instance?If you just added the paths to your system's PATH variable, you sometimes need to restart your computer, so you might as well give that a try.

You are probably building a release version using the debug libs, or vice versa. If you are building a release version, use the .lib files without a 'd' at the end, if you are building a debug version, use the .lib files that end with a 'd'.

Are you sure about the .lib files? You said in your first post:"and give me message said the program can't start because opencv_core242d.dll is missing"

If the program is looking for a *d.dll file, it means you are using a *d.lib file. I suggest you look over your .lib files and make sure you are not using any debug libraries.If that's not it, I'm a afraid I'm at a loss here. The only reason I have ever seen for producing these "weird" errors is using the wrong version of libraries.You haven't changed anything else in your build configuration, have you?

The error does not reappear, because your system can now find the file. But that still leaves me wondering why it would look for a debug dll in a release build. This can only mean that you have changed the runtime in your release build settings, which make it look for debug libraries, even though you have set it to release build. I assume you have been trying some other settings in the configuration when it couldn't find the dll's or something.

I suggest restarting from scratch with a new solution, to make sure this is not the problem.

These contained the tbb libraries in the 2.4.2 version. They allow for multi-threading within the OpenCV libraries. It seems they changed this in version 2.4.3. If it compiles and runs, you're probably ok. Anything built against version 2.4.2 wouldn't run without this path, so I guess if it can run without it now, it won't need it at all.

I am trying to run the sample code of face detectt give the error.it gives the fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? but when I include "StdAfx.h" it gives the following error 'OpenCVTest.exe': Loaded 'C:\Users\XYZ\Documents\Visual Studio 2010\Projects\OpenCVTest\Debug\OpenCVTest.exe', Symbols loaded.'OpenCVTest.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'D:\OpenCV2.4.2\opencv\build\x86\vc10\bin\opencv_core242d.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.'OpenCVTest.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.'OpenCVTest.exe': Loaded 'D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10\tbb_debug.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'D:\OpenCV2.4.2\opencv\build\x86\vc10\bin\opencv_imgproc242d.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'D:\OpenCV2.4.2\opencv\build\x86\vc10\bin\opencv_highgui242d.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file

'OpenCVTest.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16385_none_ebf82fc36c758ad5\comctl32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\avifil32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\msacm32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\msvfw32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\avicap32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'D:\OpenCV2.4.2\opencv\build\x86\vc10\bin\opencv_objdetect242d.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\ProgramData\Browser Manager\2.3.787.43\{16cdff19-861d-48e3-a751-d99a27784753}\browsemngr.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\imagehlp.dll', Cannot find or open the PDB file'OpenCVTest.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB fileThe program '[56520] OpenCVTest.exe: Native' has exited with code -1 (0xffffffff).

There is no actual error in your message. All the warnings "Cannot find or open the PDB file" are just warnings and can be ignored. They just tell you there is no debug information for the system dll's, which is normal.

All I can give as advice for this is to check your system's PATH variable and restart Visual Studio or your computer after that. Hopefully that solves it.

I'm afraid there's too little information in the error to determine what's happening. You could try debugging the code and stepping through it line for line, so you can determine what line of code is producing the error. I expect you have an empty Mat object that is passed to a function, this usually results in a program exit.

Dear Michael,Thanks for this wonderful and easy to follow guide but unfortunately, I stuck at the result! :(I'm having the same problem as Adam. Everything went well except the output window which is showing a gray screen instead of the image. I've tried changing the image path, also added sleep function but nothing worked.Any solution?

Please try removing the backslashes (\) and replacing them with forward slashes (/). So for instance if you have your image at "D:\Images\MyImage.jpg", use it like cv::Mat img = cv::imread("D:/Images/MyImages.jpg");Hopefully this works.You might want to check whether the image is empty right after reading it, you can check that with the call:img.empty();It will return true iff the image is actually empty.

This can also happen if you are using the debug libraries in a release build or vice versa, so please check whether you are using the right ones (those ending with a 'd' are for your debug build, those without the d are for release builds).

I got it working using your blog as well as referring some other places. Thanks! You can find the tutorial I wrote here: http://karanjthakkar.wordpress.com/2012/11/21/usin-opencv-2-4-2-with-visual-studio-2012-on-windows-7-64-bit/

It is used for pre-compiled headers. It's a trick to speed up compile times on large projects. You probably don't need it most of the time, but VS uses it per default.If you want to get rid of it, just remove the file and look in your project settigs. There should be a setting somewhere like "use pre-compiled headers". If you switch it off, it won't be looking for the StdAfx.h file anymore.