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++.)
Now press F5 and it should build and run!

Or, if you like to use the 2.x C++ style, you can also use:

#include "stdafx.h"
#include <stdlib.h>
#include <cv.hpp>
#include <cxcore.hpp>
#include <highgui.h>


int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat img = cv::imread("D:\\funny.jpg");
    cv::imshow("OpenCV",img);

    cv::waitKey();

    return EXIT_SUCCESS;
}

Please let me know if this worked for you!

297 comments :

«Oldest   ‹Older   201 – 297 of 297
Unknown said...

We are running the OpenCV2.4.2 people detect builtin code .It gives the following
"The code exits with 0"
and no output is displayed.

Michael Jepson said...

Hi Laiza,

I'm afraid you'll have to debug the code and step through it one line at a time, so you can identify the line of code that is causing the exit.
An exit value "0" normally indicates a "normal" exit, so probably somewhere showing results is skipped or something and the program just exits.
Good luck!

Regards,
Michael

Pushpendra Paliwal said...

worked perfectly

Anonymous said...

hello

I have compiled your code and got this error :

1>------ Build started: Project: bappy3, Configuration: Debug Win32 ------
1> bappy.cpp
1>c:\program files\opencv\build\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\vc\include\stdio.h(234) : see declaration of 'fopen'
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\Administrator\my documents\visual studio 2010\Projects\bappy3\Debug\bappy3.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Unknown said...

hello

I have been seeing you are very active. I am new user to visual studio + opencv . I want to know that , is it possible to to use your tutorial for :

Windows XP 64bit + visual C++ 2010 + OpenCV 2.4.3

Unknown said...

i have got this error : please help

'bappyx.exe': Loaded 'C:\WINDOWS\WinSxS\wow64_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.3790.4770_x-ww_8D2E3180\comctl32.dll', Symbols loaded (source information stripped).
'bappyx.exe': Loaded 'C:\WINDOWS\SysWOW64\uxtheme.dll', Symbols loaded (source information stripped).
'bappyx.exe': Loaded 'C:\WINDOWS\SysWOW64\MSCTF.dll', Symbols loaded (source information stripped).
'bappyx.exe': Loaded 'C:\WINDOWS\SysWOW64\apphelp.dll', Symbols loaded (source information stripped).
'bappyx.exe': Loaded 'C:\WINDOWS\SysWOW64\MSCTFIME.IME', Symbols loaded (source information stripped).
First-chance exception at 0x7d4e237e (kernel32.dll) in bappyx.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011f6fc..
Unhandled exception at 0x7d4e237e (kernel32.dll) in bappyx.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011f6fc..
The program '[4280] bappyx.exe: Native' has exited with code 0 (0x0).

Michael Jepson said...

Hi Anonymous,
Your main function cannot be found, make sure it is there and set as entry point. If unsure, you can also just create a new project. Do not remove the initial "main" function, just paste the code that goes inside it.

Regards,
Michael

Michael Jepson said...

Hi Dewan,

Yes it is. First decide whether you want to create a 64 or 32 bits application. If you create a 32 bits application, you can just use the guide as it is. If you want a 64 bit application, note the parts where you include various directories, there are other directories with 64 bit libraries, but they are mentioned in the guide itself.

Any cv::Exception objects can be caught, by placing a try-block around the call that produces it, catching it as "catch(cv::Exception ex) { printf(ex.what()); }" will show you the error within.
Most likely: the cv::Mat object is empty, which will produce an error when you use it, you can check this with the method ".empty()", which will return true iff the Mat object is empty.

Regards,

Michael

Unknown said...

hello Michael

thx for your reply .. i did not see your post.. so i was asking again and again.. i have configured as you have suggest ... there is no problem with the build ... but when i debug it .. it gives me only a gray window... and debug stopped... by saying this :
The program '[1276] xiv.exe: Native' has exited with code 0 (0x0).

Please help me .. thx

Michael Jepson said...

Hi Dewan,

Like I said, put a try/catch around the call that is producing the cv::Exception. If unsure, use a breakpoint and go through your code step by step to find that line of code.

Regards,

Michael

Unknown said...

hello Michael

i think it can not read the image ...
what should i do ?

Michael Jepson said...

Hi Dewan,

Please check the included libraries. Use the ones with a 'd' in the end for a debug build and those without a 'd' for a release build. That's one of the more frequent reasons for these problems.

You might also want to restart your computer after setting the PATH variables, as this seems sometimes necessary.

Regards,

Michael

Unknown said...

I have done what you have told me and got the error :

'xv.exe': Loaded 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\xv\Debug\xv.exe', Symbols loaded.
'xv.exe': Loaded 'C:\WINDOWS\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'xv.exe': Unloaded 'C:\WINDOWS\SysWOW64\kernel32.dll'
'xv.exe': Loaded 'C:\WINDOWS\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'xv.exe': Loaded 'C:\WINDOWS\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'xv.exe': Loaded 'C:\opencv\build\x86\vc10\bin\opencv_core243d.dll', Cannot find or open the PDB file
'xv.exe': Loaded
'xv.exe': Loaded 'C:\WINDOWS\SysWOW64\MSCTFIME.IME', Symbols loaded (source information stripped).
First-chance exception at 0x7d4e237e (kernel32.dll) in xv.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011ed78..
Unhandled exception at 0x7d4e237e (kernel32.dll) in xv.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011ed78..
The program '[1248] xv.exe: Native' has exited with code 0 (0x0).

Michael Jepson said...

Hi Dewan,

Please add a try/catch block around the line of code that produces the error. If you catch the exception, you can see what's in it (us its "what()" method). I can see you're not doing this, as you have an "unhandled exception", i.e. an exception which is not caught in a try/catch block.

If your image is empty, check your includes, your lib files and directory and above all, check the path to your image file. Remember to NOT use single backslashes in the path string, replace them with double backslashes or forward slashes.

Regards,
Michael

Unknown said...

hello

I am sorry .. i am really new in this area .. i did not know how to use try/catch statement... but i have tried to debug step by step and found that the image is empty image without like .. rows and columns with 00000 ... can you please help ... i am really sorry to asking you again and again..

Unknown said...

hello michael

thank you very much . At last it worked.. I have done mistakes during reading the image. Again i am sorry to bother you again and again.

Your tutorial really helps me.

regards
Dewan

Rahul said...

Hey Michael,
Thanks for the tutorial, you have helped enough by this tutorial and the comments were very much helpful for setting up OpenCV.
Thanks once again!

Anonymous said...

I searched net and used all things but failed to taste the success in installing and using open cv with VC++ this post showes me the path to success thanks very much

andohndell said...

great work :)

this is the simplest and easiest example i have ever seen. it works fine to me. thanks very much

Anonymous said...

Are there built-in functions for face detection and recognition in OpenCV r2.4

Michael Jepson said...

Hi anonymous,

Yes there are functions. OpenCV has CascadeClassifiers, including training data, for detection and various implementations for recognition. See docs.opencv.org for more information.

Regards,
Michael

Unknown said...

Hi Michael,

After following the setup process,when i build the program I get a popup window saying that the project is out of date and when i select build,the error says unable to start the program,the system cannot find the file specified(.exe file).
Could u pls help me on solving it.
THank you

Michael Jepson said...

Hi Kapish,

Did you try restarting Visual Studio or your computer? Sometimes Visual Studio keeps a handle to the .exe or .dll file it builds and because of that is unable to rebuild it.
Hopefully that helps.

Regards,
Michael

Unknown said...

dear michael,
i want to ask you how to create an executable application of opencv, that are able to be run in other pc without setting the environment or having the IDE.

Thank you. :)

Michael Jepson said...

Hi Elisa,

You can just build your application and copy everything in its (release) build directory to another computer. You'll also need the dll's from the folders that you added to you system's PATH variable. You can copy these in the same folder on the new computer and it should work.
Depending on the functions you use in OpenCV, you don't need every dll. You can use software like dependency walker to determine exactly what dll's your software requires.

Regards,

Michael

Anonymous said...

hi.i am using opencv 2.4.2 with visual studio 2010 c++. when i build it doesn't give any error bt while debugging the error shows:
'SURF.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\avifil32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\msacm32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\msvfw32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\avicap32.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'S:\OPENCV242\build\x86\vc10\bin\opencv_imgproc242.dll', Cannot find or open the PDB file
'SURF.exe': Loaded 'S:\OPENCV242\build\x86\vc10\bin\opencv_objdetect242.dll', Cannot find or open the PDB file
Native' has exited with code -1 (0xffffffff).
please help me out. I am not getting why these are missing?

thank you.

Michael Jepson said...

Hi Anonymous,

There's probably something wrong with your code itself. You can try stepping through it line by line using the debugger.
The warnings about missing .pdb files can be ignored. Pdb files contain debug information on dll's and for pre-built dll's these are often missing (you can't debug system dll's for instance).

Regards,
Michael

Anonymous said...

hey thanx for help. I tried by step but i am not getting any error. it just shows blank screen.and shows
Native' has exited with code -1 (0xffffffff).
thanx.

Michael Jepson said...

Hi Anonymous,

The fact that you get an empty Window indicates that something went awry. You can check whether your image has anything loaded with a call to .empty(). It returns true iff the image is actually empty.
Most often made mistake is to use single backslashes (\) in file paths, these don't work, you have to replace them with double backslashes (\\) or forward slashes (/).
Also, does your code even hit the waitKey(); line and if so, does it wait there?

Regards,
Michael

Anonymous said...

hey...I have done this also. Thing is that i am doing surf detection code. and I am getting this error, for displaying video, my code works fine..so what is the problem?

Michael Jepson said...

Hi Anonymous,

Well, like I said, the warnings about the missing PDB files can be ignored, they are no cause for errors.
A return value of -1 probably means that there is an exception thrown somewhere. There must be one line of code where things go wrong, so you should be able to find that line using debugging.
You can also put some try/catch blocks in your code, so you can see what's in the exception. This usually gives you a better idea of what is wrong, probably an assert or something which is failing.

Regards,
Michael

John said...

I have a problem. I followed your guidelines step by step. I am trying to run one line of code
IplImage *img = cvLoadImage("butterfly.jpg");

but I keep getting an error that says

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

Why is that?? If it is of any help I am using Visual Studio 2010

Michael Jepson said...

Hi John,

It basically means it can't find the dll. Either you didn't (properly) add the paths to your system's PATH variable, or your system is unaware of the change.
Please check if they are added properly, if the dll is actually in these folders and you might want to try restarting visual studio or your computer, to make sure the change gets noticed.

Regards,
Michael

John Demetriou said...

it was all fixed with a restart :D
thanks

Anonymous said...

Hi,

Thank you for the post. My installation went very well but I have one problem. Console window won't close even after opencv application has closed. My OS is wind 7 64bt. MSV express C++ 2010. I did not have any problem with opencv 2.2. Please help
Jo

Michael Jepson said...

Hi Jo,

Did you access a camera (using a CvCapture object) or anything? Otherwise you could just press the 'stop' button in Visual Studio's debugger (assuming you are running in debug mode), that will force it to stop. If in debug mode, you could also pause it and see where it hangs (if it does). The example should reach the return statement and exit normally.

Regards,
Michael

Anonymous said...

Hi Michael,

Thanks for the prompt reply. I can run the exe without any problem when I termianted the program. The program closes down but console window stays on. I suspect it is something do with my coding here is my code;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "stdafx.h"
#include "iostream"
#include "highgui.h"
#include "cv.h"
#include
#include
using namespace std;
using namespace cv;



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

CvCapture* capture = cvCreateCameraCapture(3);
IplImage* frame = cvQueryFrame( capture );

VideoWriter record("c://RVideo.avi", CV_FOURCC('D','I','V','X'), 30,cvGetSize(frame) , true);

if( !record.isOpened())
{
printf("VideoWriter failed to open!\n");
return -1;
}
namedWindow("video",1);
for(;;)
{


frame = cvQueryFrame( capture );

// show frame on screen
cvShowImage("video", frame);

//press ESC to exit
char c= cvWaitKey(33);
if(c == 27) break;
frame = NULL;
}
cvReleaseImage(&frame);

cvDestroyWindow( "video" );

return 0;
}

Please advice.

Michael Jepson said...

Hi Jo,

You have to release the capture object as well. You can do this with cvReleaseCapture().
BTW, if you are using C++ as language, it's nicer to use the cv::VideoCapture object, rather than the C-style CvCapture, and you can use cv::Mat rather than IplImage (just tips).
The cv::VideoCapture object can be released with a standard 'delete' method:
delete capture;

See docs.opencv.org for all C++ information.

Regards,
Michael

andohndell said...

fine article, great work

Anonymous said...

Hi Michael,

Thank you! Thank you!. You made my day. It worked as soon as I released the capture. Thank you once again. I am new to opencv and working on project, once I finish the code I would like to send it you and get some advice. Can I have your email address?

Thanks once again for the help.

Best regards
Jo

Michael Jepson said...

Hi Jo,

If you upload it somewhere, you could send it to me on Twitter (link is on the blog), but no promises!

Regards,
Michael

Anonymous said...

Hi Michael,

This is what I am trying do;

I am updating reference frame every 14seconds to accomdated the gradual change in light change in the back ground.

convert color to gray by cvCvtColor

cvAbsDiff(pre_image, cur_image, diff_img);

cvSmooth(diff_img, dif_img, CV_MEDIAN);

cvTreshold(diff_img,100,255,CV_THRESH_BINARY)

Then using
cvFindContours to find the contours
If contours ----> MOTION

Once motion is detected. It will stop upating the previous frames.

If a person walk out after motion detection. it has to go into a mode to check only if some body has fallen on the ground.

I implemented this after motion detection no updates of previous frame. THEREFORE the frame which was taken before motion was detected becomes the reference. If contours are present for a x no of seconds then it will "man on floor". The problem with this one is that when floor has dark coloured carpet and person whereing dark clothes, it will not work. Hence to detect man on floor i dynmically changed cvThreshold level to 30, 200 but it seems to give false alarm. Is there a better way of doing it. Thanks in advance.
Jo

Michael Jepson said...

Hi Jo,

Take a look at the BackgroundSubtractorMOG and BackgroundSubtractorMOG2 classes. They provide good alternatives for detecting objects in frames. When giving it a frame, you can supply a second parameter '0' to indicate it shouldn't be used to update the model.
Both classes use a 'Mixture of Gaussians' approach to create a statistical model of the values of pixels, which will probably provide better segmentation then your approach of just taking the difference between two frames.
As long as the background is fairly static, it will use relative strict models and will accept pixels as 'changed' when falling outside of the range seen during training.
You can give it a new reference image every x seconds without the second parameter, to keep its model of the background up to date.

Regards,
Michael

Anonymous said...

Hi Michael,

Thank you. I will play with it and let you know the out come.

Thanks once again.

Jo

Jo said...

Hi Michael

I was able to use backgroundSubtractorMOG2 to seprate background and foreground. How can I track a person in it? Let say person walks int particular region of interest then printf("alarm")and other regions don' care if person is in or out. I changed the foreground image to binary to find the contours and looked at size of it, so I can use it to generate a alarm when it go over by particular size but it did not do any good.

Thanks for your help.
Jo

Michael Jepson said...

Hi Jo,

I'm not sure I understand your question, but if you want to determine whether a 'blob' enters a certain region, you can calculate its bounding box (or bounding rect I think it is called in OpenCV) and use that to determine the location. You can also find the Center of Mass, using the Moments (cv::Moments) of the contour.
The coordinates of the CoM are calculated from the moments like this:
CoM.X = m10 / m00, CoM.Y = m01 / m00.

The area (size) of a blob can be calculated using its contour and cv::contourArea().

Regards,
Michael

Jo said...

Hi Michael,

Thank you for the info, I will look into it. At the moment I found a way to solve the problem. This is what I am doing; I am seprating the frame into 3 areas. If somebody move into the centre area, program should not do anything but when it sees a person in the left or right area it has to send a message to the serial port. At the moment I am doing this by gettting the mean value of the pixel of the fore-image of ROI and if it goes up by certain value then movement is detected. One draw back here is when light levels are low this value has to be reduced. I want to make my program smarter it will decide on this value dynamically depending on the light level.

Thanks once again for your advice
Jo

Anonymous said...

Following error ocurred on executing the code:
"c:\opencv\build\include\opencv\cv.h(63): fatal error C1083: Cannot open include file: 'opencv2/core/core_c.h': No such file or directory"
Help me out !!

Michael Jepson said...

Hi anonymous,

Check your Additional Include Directories. They should be added to your project properly. You can also check if the files are actually in these folders.

Regards,
Michael

Jo said...

Hi Michael,

Good Day!

It is Jo again. My program seems to be working fine. Now I want to port this code execute from Rasberry pi. These are my thoughts but no idea whether it will work or not.

I want install qt in my windows 7 laptop and port the code to qt and compile it for Linux Environment and then transfer the exe and dll files to the Rasberry pi and run the program. Which Linux version is good for this. Am I on the right track?

Tahnks once again.
Best Regards
Jo

Unknown said...

Thanks so much! It took me more than 3 hours to install OpenCV and configuring it, I found your site on google and absolutely relax me from OpenCV, I created and run my first application!

Thanks a gain! :D

Innam Hunzai said...

LINK : fatal error LNK1104: cannot open file 'opencv_core245.lib' please help

Anonymous said...

hello bro..
why this happen to me??
1>c:\project\opencvtest\opencvtest.cpp(5): fatal error C1083: Cannot open include file: 'cv.h': No such file or directory

why it does not have that file??should i download it or what?

Michael Jepson said...

Hi Anonymous,

See this part:
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

You can just use Windows Search if it still misses the file to see where it is. The directory it's in should be added as additional include directory.

Regards,

Michael

Michael Jepson said...

Hi Innam,

You're missing a library directory.
See this part:

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!

Regards,

Michael

Dharanish said...

Hi Michel,
I have followed the steps you have mentioned. I am getting a system error
"The program can't start because opencv_core242d.dll is missing from your computer. Try reinstalling the program to fix this problem."
I have added the path
"C:\OpenCV2.4.2\opencv\build\x86\vc10\bin" which is my directory path in the path variable.

Am i missing something

Regards
Dharanish

Michael Jepson said...

Hi Dharanish,

Sometimes you need to restart Visual Studio or even your whole computer before the changes in the PATH variable go live.
I hope this is the problem you're having.

Regards,
Michael

Anonymous said...

simple and nice tutorial for 1st opencv program.
Thanks buddy

Shyama said...

Hello sir,
Im new to opencv and am trying to install opencv 2.4.5 with visual studio 2012. Im getting the following error when I run the code:


#include "stdafx.h"
#include
#include
#define _CRT_SECURE_NO_WARNINGS

int main()
{
IplImage* img = cvLoadImage("C:/Users/Shyama Panolth/Pictures/Images/Hardeep Singh.jpg");
cvNamedWindow("MyWindow");
cvShowImage("MyWindow", img);
cvWaitKey(0);
cvDestroyWindow("MyWindow");
cvReleaseImage(&img);
return 0;
}


Error : C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

Unknown said...

Hello every body
i follow all steps
but finaly i saw this error :
""error lnk1112 module machine type x64 conflicts with target machine type x86""
What can I do?
plz

Michael Jepson said...

Hi Mohammad,

It means you are using the 64 bit libraries, while trying to create a 32 bit build. You can either change your build configuration in Visual Studio to actually create a 64 bit build, or you can switch to the OpenCV 32 bit libraries. Please note that the will always have to match and that a 32 bit build will run on both 32 and 64 bit computers, while a 64 bit build will only run on 64 bit computers.

Regards,
Michael

Michael Jepson said...

Hi Shyama,

Is your program actually halting on this error? It seems more like a warning to me, not a reason for your program to fail the build.
Does your code build and start?

Regards,
Michael

Kgabo S said...

Good day, What causes this error? error LNK1123: failure during conversion to COFF: file invalid or corrupt

Kgabo S said...

This pops up when I try debugging the sample code.

Michael Jepson said...

Hi Kgabo,

You have probably installed VS 2012 after installing VS2010C++. It happens that the installation of 2012 breaks the C++ compilers of VS2010.
See this MSDN thread for more information:
VS2012 RC installation breaks VS2010 C++ projects

Regards,
Michael

Unknown said...

Hi Michael,
I followed your instructions, tried all ways including discussions in previous comments. However, error still exists. It reads:
'OpenCVTest.exe': Loaded 'C:\Users\Andante\Documents\Visual Studio 2008\Projects\OpenCVTest\Debug\OpenCVTest.exe', Symbols loaded.
'OpenCVTest.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll'
'OpenCVTest.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'OpenCVTest.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'OpenCVTest.exe': Loaded 'C:\opencv242\build\x86\vc9\bin\opencv_core242d.dll'
'OpenCVTest.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcp90d.dll', Symbols loaded.
'OpenCVTest.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll', Symbols loaded.
'OpenCVTest.exe': Loaded 'C:\opencv242\build\common\tbb\ia32\vc10\tbb_debug.dll'
'OpenCVTest.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll'
The program '[7980] OpenCVTest.exe: Native' has exited with code -1073741515 (0xc0000135).

it announced the file mscvr100d.dll missing...

I tried to reinstall Visual Studio, installed Visual C++ distributed packages, downloaded and copied to working directories files .dll missing... but errors still there.
COuld you please give me a hint for this struggle?
Thanks.

Michael Jepson said...

Hi Andante,

The best I could find for this was this forum thread:
Missing msvcr100d.dll

I hope it can help you solve your problem, but I expect you've already found and tried this.

Regards,
Michael

Michael Jepson said...

Hi Andante,

I just noticed this line in your output:
Loaded 'C:\opencv242\build\x86\vc9\bin\opencv_core242d.dll'
It seems like you are using the VS 2008 dll's of opencv. There should be a folder vc10 rather than vc9 for Visual Studio 2010.
I hope that's your problem.

Regards,
Michael

Greg San Diego said...

im very anxious to try to learn how to use visual studio c++ 2010 express and open cv 2.4.5. ive followed your blog steps to the letter (except that i did not the the instruction referencing 'D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc10' as i do not run 'itanium' platform).
yes ive replaced your 'd:\opencv2.4.2\' path with my 'c:\data\lib\opencv245\' path and the link to the graphic file. when i try to compile i get this error...

1>------ Build started: Project: 001opencv_display_jpg, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'opencv_calib.obj'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

to note, ive not compiled a c program for over 20 years, so i am more than rusty here, and ive never really ever had to link against 3rd party libraries as we are doing here. im confused by the reference to 'opencv_calib.obj' i assume this is an object file that the compiler was to have built??? but why isnt it referencing ''opencv_calib245d.obj'? i am begging here for some help.

Michael Jepson said...

Hi Greg,

Sorry to say I have never encountered a problem with a .obj file. If you do a search on the OpenCV folders, is there any such file as the linker is searching for? If so, you might try and add that directory (and maybe even the file(s) itself) to the linker setup in the configuration (as I've done in the guide with the .lib files). Hopefully that will solve your problem.

Regards,

Michael

Anonymous said...

well, seeing as i did NOT follow one line of your instruction (thinking because i was not on 'itanium' platform), perhaps this is the problem. i did not put into my path envvar '...opencv\build\common\tbb\ia32\vc10'. my question to you is, 'should this folder exist after installing opencv?' as after a fresh install, i find this folder does NOT exist. under '...opencv\build' there is no 'common' sub folder. perhaps this is the issue?

Michael Jepson said...

Hi Greg (I think?),

The common folder only contains 3rd party libraries, such as Intel's tbb. But the opencv libraries (such as the opencv calib you seem to be missing) should be in D:\OpenCV2.4.2\opencv\build\x86\vc10\lib (or your variant thereof).
But I only have .lib files in these folder, no .obj files, so I'm still at a loss what's going wrong for you.
Or are you by any chance building OpenCV itself? That would (and should) produce obj files during that task.

Regards,
Michael

Anonymous said...

i figured it out. i evidently read your page that speaks to entering the program and compiling it. perhaps there was a different page i did not see that spoke about the requirement to use intel's 'tbb' (threading building block) library as well. there are several ways one can add this functionality to vc++, using the tbb 'visual studio plug-in', copying all of the tbb *.dlls into one of your existing opencv search path folders, or unzipping the entire 'tbb' library into where you store your general 3rd party libraries and adding the '...\tbb##\bin\ia32\vc##' and '...\tbb##\bin\ia32\vc##\irml' dirs to your path env var. i opted for the latter method. and now it compiles !!! thanks.

Unknown said...

It is a really good complement to the guide at willowgarage.

Thanks for your help, Michael.

Unknown said...

hello

attempt to obtain the coordinates x, y of an object to measure its speed in a particular area, but the speed of the movement is fast and I have not the number of samples per unit time need ... I'm using filtering by color, question is:

1) is faster using detection using contour or color?

2) depends on the webcam, how many frames per second can take? this amount is configurable with opencv?

3) It is for hardware capacity? my settings
-use c + +
-Quad-Core Q6600, 2.4GH
-2 GB RAM 800 mhz
-Gforce 8600 gs

Thank you!
by Dani Cortizo

Michael Jepson said...

Hi Laiza,

What approach is faster is fully dependent on how you do them and on what resolution, but my first guess would be that colour segmentation is easiest and quickest.
As to the processing speed: Do you use multiple threads to make the most use of your CPU? Also, don't forget that USB2 has limited bandwith, at 2MPixel with no compression (don't use MJPG as it has a very negative influence on image quality for Computer Vision) you cannot get much more than 2 or 3 frames per second over a USB2 port.
There are USB3 cameras which can reach much higher speeds, but they are quite expensive.

You can control the FPS with OpenCV, but you can test with other software what the highest possible settings are for your camera. Remember: the higher the resolution, the lower the framerate.

Regards,
Michael

Unknown said...

This is the first time I am working with opencv in Visual Studio. I have worked in ubuntu though. I was trying to install opencv.
1.I extracted it. Edited the path variable in system properties as D:\opencv\build\x64\vc10\bin

2. I set VCC++ directories as $(OPENCV_BUILD)\x64\vc10\lib;$(LibraryPath).

3.C/C++ additional include directories as $(OPENCV_BUILD)\include\opencv;$(OPENCV_BUILD)\include\opencv2

4. Linker-> input additional dependencies as opencv_core243.lib opencv_imgproc243.lib opencv_highgui243.lib opencv_ml243.lib opencv_video243.lib opencv_features2d243.lib opencv_calib3d243.lib opencv_objdetect243.lib opencv_contrib243.lib opencv_legacy243.lib opencv_flann243.lib

I am using the following sample code:
// OpenCVTest.cpp : Defines the entry point for the console application.
include "stdafx.h"
include
include
include
int _tmain(int argc, _TCHAR* argv[]) { IplImage *img = cvLoadImage("C:\Users\firstMap"); cvNamedWindow("OpenCV",1); cvShowImage("OpenCV",img);

cvWaitKey(0);
cvDestroyWindow("OpenCV ");
cvReleaseImage(&img);

return 0;
}
I am getting the following error :: fatal error C1083: Cannot open include file: 'opencv\highgui.h': No such file or directory

Michael Jepson said...

Hi Aditi,

There is tiny mistake in your step 3: $(OPENCV_BUILD)\include\opencv; Should be $(OPENCV_BUILD)\include; For some reason the default is that and for opencv2 you add \opencv2.
That is because all references to the header files are as 'opencv/highgui.cs', so if you already added the 'opencv/' part, it won't find them.

Good luck!

Regards,
Michael

Anonymous said...

\myopencv\myopencv\myopencv.cpp(3): fatal error C1083: Cannot open precompiled header file: 'Debug\Myopencv.pch': No such file or directory


Why am i getting this error?

Michael Jepson said...

Hi Anonymous,

You probably have "use precompiled headers" switched on in your project. If you look in the project properties (not sure where by heart), you'll find a setting. Try switching it off.

Regards,
Michael

moshii said...

Thank you very very much. I spent couple of days to configure but failed. Then i found your blog and now my opencv working well.

Ricardo said...

Hi Michael!

Completely off-topic... but I noticed you have solved your blogger problem where it was showing only the first 200 comments on this post. I'm having the same problem... Could you tell me how you changed the "Load more..." link to "Newer" and "Newest"? :)

Thanks!

PRAKASH said...

Error 1 fatal error C1083: Cannot open include file: 'opencv2/imgproc/imgproc.hpp': No such file or directory i:\Projects .net (ZAROONS-PC)\ImageSearching\MatchTemplate_Demo.cpp 9 test


I am getting this error while running MatchTemplate_Demo.cpp at #include "opencv2/imgproc/imgproc.hpp"

nurhanna said...

spent 2 days to try installing opencv on my machine, thanks a lot found your blog here! it works!

iANAND- Ice Ice Baby said...

Hello Jepson.

Can you elaborate the pre installation requisites.

I am downloading opencv 2.4.2 exe.

Will it contain the build directory structure or do i have to use the Make File app.

Michael Jepson said...

Hi Eyeanand,

The installer will contain the build directories. For use with Visual Studio there is no need to use any make utility.

Regards,
Michael

Rietykity said...

Hi Michael...
I am facing a virtual problem with opencv. i am using 64bit win7 and vs2010. When i run face_detection program it just open camera window and does not detect the face(in 64bit debug). But same code when I run in my friend's computer of 32bit win7 it works fine. So should i do to fix the problem.
[i have tried that code in 32bit debug by suitable configuring property_manager in my computer it compiled successfully even. But gives run time error of 0x0000007b and terminate with showing c:\windows\sysWOW\kernel32.dll cannot open.]
[I downloaded new kernel32.dll but it not copying in c:\windows\sysWOW folder]
Please help
Thank You

Unknown said...

hello , i m i m trying open cv with visual c++ 2010 and i m getting this error 1>------ Build started: Project: OPENCV-TEST, Configuration: Debug Win32 ------ 1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
can any one help me.thanks:)

Anonymous said...

It worked for me, thanks a lot! :)

Unknown said...

i m getting error like
Error 1 fatal error C1083: Cannot open include file: 'cv.hpp': No such file or directory c:\users\intel\documents\visual studio 2005\projects\opencvtest\opencvtest1\opencvtest1\opencvtest1.cpp

Michael Jepson said...

Hi GOUTAMI B GABASAVALAGI,

Check your "Additional Include Directories" in Visual Studio. The file should be in one of these folders and the paths should be added to these in Visual Studio.

Regards,
Michael

Anonymous said...

Error 1 error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.


Error 2 error C1075: end of file found before the left brace '{' at 'Segmentation.cpp(11)' was matched


are my errors .. can u plz help me out ??

Michael Jepson said...

Hi Anonymous,

The first is just a warning, it says how to disable it.
The second is a fault in Segmentation.cpp. It tells you that the left brace ('{') isn't matched before the End-Of-File was found. This just means that you have at least one more '{' in your file than you have '}'. These should match, for every '{' you should have a matching '}'.

Regards,
Michael

Charis Faridchie Siswoyo said...

i got this error,,how to fix it???

Error 1 error LNK1104: cannot open file 'opencv_calib3d2411.lib' c:\Users\win\documents\visual studio 2010\Projects\coba cv\coba cv\LINK coba cv

Michael Jepson said...

Hi Charis,

Did you add the path to the .lib files to the Additional Library Directories? Are you doing a debug build? If so, the library files should end in *d.lib.
Is the file actually there with the exact name?

Regards,
Michael

Beenish143 said...

Hello.. I'm using Visual studio 2010 and i downloaded opencv2.4.11 and configure it according to your described steps..but it is showing the error while debugging, error is Fatel error lnk1181: cannot open input file 'opencv_calib3d2411d.lib'

plz help me how to sort out this problem

Harsha Khiroya said...

Hello,Michael
I am working with a code that finds moving vehicles. When I added the find contours method, that's where the program has struct.It is showing unhandled exception at memory location....
The code is as follows:

bool objectDetected;
//these vectors needed for o\p of contours
vector>contours;
vector hierarchy;

//find contours using findContours funtion
//findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE);//retrieves all contours
findContours(dstimg, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Approximate contours to polygons + get bounding rects and circles
vector > contours_poly( contours.size() );
vector boundRect( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}
/// Draw polygonal contour + bonding rects + circles
Mat drawing = Mat::zeros( dstimg.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours_poly, i, color, 1, 8, vector(), 0, Point() );
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
}
/// Show in a window
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
imshow( "Contours", drawing );
/* if(contours.size()>0)objectDetected=true;
else objectDetected = false;

if(objectDetected)
{
vector< vector >contours_poly( contours.size());
vector< Rect >boundRect( contours.size());
for(int i=0;i(),0,Point());
rectangle(drawing,boundRect[i].tl(),boundRect[i].br(),color,2,8,0);
}
//namedWindow("Contours",CV_WINDOW_AUTOSIZE);
imshow("contours",drawing);
}


Please help.Thanks in advance.

«Oldest ‹Older   201 – 297 of 297   Newer› Newest»