Skip to main content

Install OpenCV with Visual Studio : Walkthrough

In this tutorial, I will show how to install OpenCV in windows and build projects with Visual Studio 2013 (and other versions). There are many ways of doing this, but I have found the following walkthrough most convenient for managing multiple projects. The Quick Setup section is a brief how-to for re-installing opencv or creating a new project for some quick simulation. The Walkthrough section is the detailed guide for beginners who don't have much experience about opencv and/or visual studio.

Quick Setup

(For users already familiar with the installation process)
  • Download opencv pre-built binaries and extract to C: drive
  • Open Visual Studio. Create a new C++ Console Application project. Go to Project Properties
  • Add C:\opencv\build\include to Additional Include Directories under C/C++ > General
  • Add C:\opencv\build\x86\vc12\lib to Additional Library Directories under Linker > General
  • Add all the files in the directory (in previous step) which end with .lib extension to Additional Dependencies under Linker > Input
    NOTE: Debug libraries have 'd' at the end of their file name (after version, before .lib extension). Add those for debug configuration and others for release configuration. DO NOT add both in same configuration.
  • Copy all the DLL files from C:\opencv\build\x86\vc12\bin to the output folder of the projects.
    NOTE: Similar naming convention is followed for DLLs. Library files ended with 'd' requires DLL files ended with 'd' and vice versa. 
The directories x86 and vc12 may be changed depending on your visual studio installation. 

Walkthrough

(For absolute beginners)
  1. Go to http://opencv.org/ and click on the link OpenCV for Windows.
    This will redirect you to the sourceforge website and the download should begin momentarily. By default, it will download the latest pre-built binaries for windows (something like opencv-<version>.exe). It is a big self-extracting archive (more than 250MB) containing both the sources and pre-built binaries for visual studio. 
  2. Open the downloaded file. It will ask for a path to extract its contents. Insert C:\ in the box.
    Extraction process will take some time. After that, you should have a folder named opencv in you C drive.
  3. Open Visual Studio and create a new C++ project (Console application)
  4. In the Property Manager window (not the Properties window. If you can not find it, activate it from View > Other Windows > Property Manager), you will see the configurations for your project: Debug | Win32 and Release | Win32. Right click on Debug | Win32 and select Add New Project Property Sheet.
  5. Enter name and location for the new property sheet.
    I used opencv_debug_win32.props for name and chose the parent folder of the solution folder. This way, same property sheet can be included to all opencv projects.
  6. Right click on the newly created property sheet and select Properties.
  7. Go to C++ > General. Click on Additional Include Directories and click . Insert C:\opencv\build\include and select OK.
  8. Go to Linker > General. In similar way, add C:\opencv\build\x86\vc12\lib to Additional Library Directories.
  9. Go to C:\opencv\build\x86\vc12\lib (folder from previous step) in windows explorer. There are some files with .lib extension in that directory. You will notice that the files are in pairs; each file has opencv_ as prefix and ends with version number, but one in each pair has a 'd' following the version number. This 'd' tells that this is debug library.
  10. Go to Linker > Input in visual studio. Add all the debug libraries in Additional Dependencies box.
    You can insert them in line by putting a semicolon between them. Alternatively, you can click <Edit...> and then insert each library in a separate line.
  11. Select OK and then save the property sheet. 
  12. Create another property sheet for release configuration following same procedure. This time, name it something like opencv_release_win32.props and select the library files without 'd' in file names in step 10.
  13. Go to C:\opencv\build\x86\vc12\bin in windows explorer. Similar to the lib folder, there are pairs of DLL files for debug and release configuration. Copy debug DLLs to debug output folder of the project and release DLLs to release output folder. If a DLL does not have a pair, copy it to both folders.
Congratulations! Your visual studio is now ready to develop opencv projects. Now, create a hello world program and test the configuration.

For new projects, you just need to follow these two steps.
  1. From Property Manager window, write click on a configuration and select Add Existing Property Sheet.... Now browse and select the property sheet created earlier for that configuration.
  2. Copy opencv DLLs to the output folder of the new project (step 13 above).

Customization

  • The paths can be customized according to your need. You can extract opencv sources and binaries to any folder of your choice (step 1). Just modify the paths in step 7 and 8 accordingly.
  • If you have 64 bit installation of visual studio, you may want to develop your projects in 64 bit. In that case, just change "x86" part of all paths to "x64".
  • The "vc12" portion of the paths may vary depending of your visual studio version. 
    • For Visual Studio 2010, it is vc10
    • For Visual Studio 2012, it is vc11
    • For Visual Studio 2013, it is vc12

Hope this helps your installation process. Feel free to comment and share the post.

Comments

Popular posts from this blog

কোটা সংস্কার আন্দোলনের ব্যাপারে আমার মতামত

সম্পাদনা: লেখা শেষ করে পোস্ট করার আগে খবর পেলাম, প্রধানমন্ত্রী সংসদে কোটা ব্যবস্থা বিলোপের ঘোষণা দিয়েছেন। যদিও আমি এর বাস্তবায়নের ব্যাপারে আশাবাদী না, তবে আমার মতে এটা সংস্কারের চেয়ে ভালো বিকল্প। মূল লেখা: গত কয়েকদিন ধরে সরকারী চাকরীতে কোটা পদ্ধতি সংস্কারের দাবীতে সারা দেশে আন্দোলন চলছে। এ ব্যাপারে আমার ব্যক্তিগত মতামত কিছুটা মিশ্র। আমি আন্দোলনের মূল দাবীর সাথে পুরোপুরি একমত নই, তবে বিশ্বাস করি যে আন্দোলনকারীদের দাবী অনুযায়ী কোটা সংস্কার করলে সেটা বর্তমান অবস্থার চেয়ে ভালো হবে। এছাড়াও আন্দোলনের পদ্ধতি, ফেসবুকে আন্দোলন সমর্থকদের প্রতিক্রিয়া নিয়ে কিছু আপত্তি আছে। সেগুলো নিয়ে নিজের মতামত তুলে ধরছি। ১. আমি মনে করি, কোটা ব্যবস্থা একটা অন্যায় ব্যবস্থা। এখানে একদল মানুষকে আরেকদলের উপর অনায্য সুবিধা দেয়া হয়। যদিও সাধারণতঃ একদল সুবিধা-বঞ্চিত 'পিছিয়ে পড়া' মাইনরিটিকে 'এগিয়ে আনার' জন্য কোটার নামে অতিরিক্ত (অনায্য) সুবিধা দেয়া হয়, মূলতঃ এটা হল একটা অন্যায়কে আরেকটা অন্যায় দিয়ে প্রতিস্থাপন করা। শাসকের জন্য 'divide and rule' প্রয়োগের হাতিয়ার। তোমার উপর দশ বছর অন্যায় করা হয়েছ...

প্রজার উপযুক্ত রাজা

গল্পটা প্রথম পড়েছিলাম নসীম হিজাযীর 'কিং সায়মনের রাজত্ব' বইয়ের ভুমিকায়। আমাদের দেশের বাস্তবতার সাথে কেমন আশ্চর্য একটা মিল এই উপন্যাসের কাহিনীর! আর উপন্যাসটা লেখা হয়েছে মূলতঃ এই গল্পকে ভিত্তি করেই। এক দরবেশ ও তার খাদেমের গল্প। তারা থাকে শহর থেকে দূরে এক বনের মধ্যে। দরবেশ সারাদিন ইবাদত বন্দেগীতে মশগুল থাকে। আর খাদেমের কাজ আশেপাশের লোকালয়ে ভিক্ষা করে খাবার জোগার করা আর দরবেশের সেবা করা। কাহিনী মোটামুটি এরকম: দরবেশ ছিলেন খুব মানবদরদী। মানুষের দুঃখ কষ্ট তিনি সহ্য করতে পারতেন না। তাই সে সবসময় আল্লাহর কাছে দোয়া করতেন, 'হে আমার মালিক, তোমার বান্দাদের দুর্দশা আমি আর সহ্য করতে পারছি না। কিন্তু তাদের যে খেদমত করব - আমার সে সামর্থটুকুও নাই। কাজেই তুমি যদি আমাকে বাদশাহ বানিয়ে দাও, তাহলে আমি দিন রাত জনগণের সেবা করব। গরীব, দুঃখী, অসহায় এবং এতিমদের সাহায্য করব। সব রকম অন্যায় ও খারাপ কাজ প্রতিরোধ করব, আর ন্যায় ও কল্যাণকর কাজে উৎসাহিত করব। রাজ্যে ন্যায় বিচার প্রতিষ্ঠা করব। অন্যায়কারীদের দৃষ্টান্তমুলক শাস্তি দেব। সব পানশালা, জুয়ার আড্ডা, অশ্লীলতা-বেহায়াপনার আসর উচ্ছেদ করব, আর সে স্থলে মসজিদ...