This tutorial guides you through the process of installing OpenCV 2.3.1 in windows using Visual Studio 10. OpenCV changes its installation process from version to version and sometimes make it too confusing to work properly. In this tutorial I’ll try to mention as much details as possible in the installation process of OpenCV.
Preparation Step: Install Visual Studio 10.
Stage One: Installing OpenCV
- Download OpenCV 2.3.1 Superpack from the following link: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/.
- Run the exe file and extract the contents in C:OpenCV231. If the contents (i.e. the folders named 3rdparty, android etc) are copied in a folder named “opencv” inside C:OpenCV231 then copy all of them to C:OpenCV231. (I’ll describe all the later steps assuming that the files has been extracted here. If not, please modify the instruction accordingly.)
- Download and install cmake from http://www.cmake.org/
- Run the Graphical User Interface of Cmake (cmake-gui).
- In the field named “Where is the source code:” white c:opencv231. In the field named “Where to build the binaries” specify C:OpenCV231msvc. Now click “configure”.
- A dialog box will appear (Figure 1) asking you to specify the generator for the project. Select Visual Studio 10 from the dropdown list. Select “Use default native compiler”. Now click “Finish”. It may ask for your permission to create a new folder named msvc. Just allow to do it. It
- Now the cmake window will look something like Figure 2. In this dialog, check the box named “install_c_examples”. Click the “Generate” button. This will make Visual Studio solutions in the C:OpenCV231msvc folder.
- Open OpenCV.sln. Select “Debug” in the solution configuration listbox. Now press F7 to build the solution. If all the projects are successfully built (3 projects may be skipped, don’t worry about that) it will show such message. Now do the same by selecting “release” in the solution configuration listbox.
- Copy the “lib” and “bin” folders from C:OpenCV231msvc to C:OpenCV231. Also copy the contents of “include” folder from C:OpenCV231build to C:OpenCV231include
- Now we need to add the following 2 folders in environment variables:
C:OpenCV231binRelease
C:OpenCV231binDebug
To do this, go to Control Panel > System > Advanced System Settings > Environment Variables and append these two folders into the “path” variable. Remember to separate the entries by semicolon. Click ok.
- Create a new Win32 console application.
- In solution explorer, right click on the project and click properties. Go to VC++ Directories. in Include Directories, add the following 2 folders:
C:OpenCV231include
C:OpenCV231includeopencv - Add the following folder in Library Directories while you are in Debug configuration:
C:OpenCV231libDebug
Add the following while in Release configuration:
C:OpenCV231libRelease - Go to Linker > Input. Add the following in the “Additional Dependencies” field while in debug configuration:
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_haartraining_engined.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib
Add the following while in release configuration:
opencv_calib3d231.lib
opencv_contrib231.lib
opencv_core231.lib
opencv_features2d231.lib
opencv_flann231.lib
opencv_gpu231.lib
opencv_haartraining_engine.lib
opencv_highgui231.lib
opencv_imgproc231.lib
opencv_legacy231.lib
opencv_ml231.lib
opencv_objdetect231.lib
opencv_ts231.lib
opencv_video231.lib - In earlier versions, OpenCV used to be included by the following line:
#include <cv.h>
From OpenCV 2.2, it is included by either the following:
#include <opencv2/opencv.hpp>
Or, by individually including each module located in different folders inside C:OpenCV231libDebug
Compatibility Issue:
I have found the following backward compatibility issue while moving from opencv 2.1 to 2.3.1
If M be a cv::Mat then if you have a command M.inv(CV_SVD_SYM) then you have to change it to M.inv(cv::DECOMP_SVD)
Update: OpenCV 2.4.0 is released. It has very similar installation process except the lib filenames. Release filenames:
opencv_calib3d240.lib
opencv_contrib240.lib
opencv_core240.lib
opencv_features2d240.lib
opencv_flann240.lib
opencv_gpu240.lib
opencv_haartraining_engine.lib
opencv_highgui240.lib
opencv_imgproc240.lib
opencv_legacy240.lib
opencv_ml240.lib
opencv_nonfree240.lib
opencv_objdetect240.lib
opencv_photo240.lib
opencv_stitching240.lib
opencv_ts240.lib
opencv_video240.lib
opencv_videostab240.lib
And Debug Filenames
opencv_calib3d240d.lib
opencv_contrib240d.lib
opencv_core240d.lib
opencv_features2d240d.lib
opencv_flann240d.lib
opencv_gpu240d.lib
opencv_haartraining_engined.lib
opencv_highgui240d.lib
opencv_imgproc240d.lib
opencv_legacy240d.lib
opencv_ml240d.lib
opencv_nonfree240d.lib
opencv_objdetect240d.lib
opencv_photo240d.lib
opencv_stitching240d.lib
opencv_ts240d.lib
opencv_video240d.lib
opencv_videostab240d.lib
আপনার সাইটা সুন্দর। মহিউদ্দিন স্যারের সুপারভিশনে OpenCV te ইমেজ প্রসেসিং এ কিছু কাজ করেছি… আমি ইমেজ প্রসেসিং এ ইন্ডেপেন্ডেন্ট রিচার্চার হিসাবে একটা পেপার লিখতে চাই। টপিকস সাজেস্ট করে সাহায্য করতে পারবেন?
azam007(at)gmail.com
একদম পেপার লেখার উপযোগী টপিক পাওয়া আসলে কঠিন। আর যদি তেমন কোনও আইডিয়া কেউ পায়ও, তাহলে ওটা নিয়ে নিজে কাজ না করে অন্যকে দেবার মত মহানুভব হওয়াটা মনে হয় আরও অনেক কঠিন। তবে আমি কিছু লিঙ্ক হয়তবা দিতে পারি যেগুলোতে ঘোরাফেরা করলে অনেক সময় মাথায় আইডিয়া খেলে যেতে পারে।
http://www.siggraph.org/
http://www-video.eecs.berkeley.edu/
http://www.cs.cmu.edu/~cil/vision.html
http://media.mit.edu/
http://johnnylee.net/projects/
Thank you very much for visiting my websight
হাহাহা… ঠিক পিনপয়েন্ট আইডিয়াটা তো চাইনি, আপনার অভিজ্ঞতা থেকে কি নিয়ে কাজ করা যায় সেটা জানতে চেয়েছিলাম। তবে দারুন কিছু সাইট দিয়েছেন। এর মধ্যে Brain-Computer Interaction টপিকস টা পছন্দ হয়ে গেল। থেক্স ভাইয়া। আর আপনার সাইট টা এমনিতে কাজের, ভিজিট করার জন্য ধন্যবাদ জানানোর দরকার আছে বলে মনে হয় না। আপনি আপনার কাজ গুলো বাংলাতে লিখেন না কেন? আমি কিছু ট্রাই করেছি ব্লগে। দেখতে পারেন
http://www.somewhereinblog.net/blog/mnazamblog/category/13526
http://www.somewhereinblog.net/blog/mnazamblog
আর আমি রশীদ হলে ২১১ তে শাহাদাত ভাইয়ের রুম মেইট ছিলাম। আপনি মাঝে মাঝে আমাদের রুমে আসতেন। পি.এলে মটর ভাইয়েরা ধুমসে তাস পিটাইতো হাবিব ভাইয়ের বেডে 🙂
অ্যানিওয়ে, আশা করি ওয়েবটা ভবিষ্যতে আরো কন্টেন্ট সমৃদ্ধ হবে। ভালো থাকবেন।
i have followed all the steps but it shows three failed.opencv_gpu is not built when i use build solution opencv.sln
In such case you should turn off the gpu checkbox while using cmake for generating the solution
Hello vaia,
It was quite a helpful description for me. Following your path I actually still stuck in same position before because i thought it might be problem for me in visual stuidion version but it really not..the thing is i want run a sample program of opencv in visual studio 2010 and actually for some wired reason it still says this error which left me still in same place as before.. can you tell what might i do to just simply run the code.
1>main.obj : error LNK2019: unresolved external symbol “void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class cv::Mat const &)” (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABVMat@1@@Z) referenced in function “public: void __thiscall App::run(void)” (?run@App@@QAEXXZ)
1>main.obj : error LNK2019: unresolved external symbol “public: virtual void __thiscall cv::HOGDescriptor::detectMultiScale(class cv::Mat const &,class std::vector<class cv::Rect_,class std::allocator<class cv::Rect_ > > &,double,class cv::Size_,class cv::Size_,double,int)const ” (?detectMultiScale@HOGDescriptor@cv@@UBEXABVMat@2@AAV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H@cv@@@std@@@std@@NV?$Size_@H@2@2NH@Z) referenced in function “public: void __thiscall App::run(void)” (?run@App@@QAEXXZ)
1>main.obj : error LNK2019: unresolved external symbol “public: void __thiscall cv::Mat::copyTo(class cv::Mat &)const ” (?copyTo@Mat@cv@@QBEXAAV12@@Z) referenced in function “public: void __thiscall App::run(void)” (?run@App@@QAEXXZ)
1>main.obj : error LNK2019: unresolved external symbol “void __cdecl cv::cvtColor(class cv::Mat const &,class cv::Mat &,int,int)” (?cvtColor@cv@@YAXABVMat@1@AAV21@HH@Z) referenced in function “public: void __thiscall App::run(void)” (?run@App@@QAEXXZ)
1>main.obj : error LNK2019: unresolved external symbol “void __cdecl cv::resize(class cv::Mat const &,class cv::Mat &,class cv::Size_,double,double,int)” (?resize@cv@@YAXABVMat@1@AAV21@V?$Size_@H@1@NNH@Z) referenced in function “public: void __thiscall App::run(void)” (?run@App@@QAEXXZ)
1>main.obj : error LNK2001: unresolved external symbol “public: virtual void __thiscall cv::HOGDescriptor::setSVMDe
The reason for getting any kind of error starting with “LNK” indicates it is a linking error. Linking error occurs when visual studio cannot establish connection between your program and the *.lib files created in libdebug and librelease folder. It is done in visual studio by following two steps. One is to show the lib folder which is done in step 3 in stage two. Another step is to specify each lib file individually which is done in step 4. Remember, each file must be separated by a semicolon in the “Additional Dependencies” field. Note that, in debug configuration, you should add the files ending with a “d” before the extension (for example, opencv_core231d.lib). On the other hand, in release configuration, add the files without the “d”. Also remember that, this instruction is for OpenCV version 2.31. If you install later version, you need to actually go to the library directory in opencv, see what are the name of the .lib files, and actually include those files instead of the ones listed here. Hope this helps.
thanks for your feedback vaia. I did checked the additional dependencies. As i am using opecv 2.3.1 the same as version you mentioned here. I did checked library path by placing flies end up with d in debug and without d in release. I don’t get it still why it shouldn’t find it. Actually the errors came for these line of code last time and commenting out that to see what happen than came this lib error..
// Create HOG descriptors and detectors here
vector detector;
if (win_size == Size(64, 128))
detector = cv::gpu::HOGDescriptor::getPeopleDetector64x128();
else
detector = cv::gpu::HOGDescriptor::getPeopleDetector48x96();
I am using ati radeon.. Is it also problem of graphics card that I am using ??
Is your card cuda supported? check here http://opencv.willowgarage.com/wiki/OpenCV%20GPU%20FAQ#What_GPUs_are_supported.3F
If not, use non-gpu version cv::HOGDescriptor
Hi tanveer,
I tried installing using ur method and ur example, when i ask for build solution it builds successfully but if I ask for start debugging it says “The program can’t start because opencv_core231d.dll is missing from your computer. Try reinstalling the program to fic this problem.”
can you please help me with this?
Thanks
Seems you’ve missed step 10 of stage one. If not, then manually check whether those folders actually contains the dll files or not. If they does not contain then check where the dlls have been generated and add those directories in the system path. You may need to restart the computer after adding the values to system path.
Hope this will work.
Dear Tanveer,
Thanks for this great tutorial. It really helped me. Anyways, apnar site ta khub bhalo. Jazak’Allah for the help. 🙂
Yes. Use VideoCapture and imwrite. Let me know if you need an elaborate answer.