Monday 6 July 2015

How to install OpenCV 3.0.0 in Windows and create a sample program in Visual Studio 2012



Hello!

OpenCV libraries are a great way to get started in Computer Vision and Image processing applications. Plus its FREE!

 It has C++, C , Python and Java interfaces and supports Windows, Mac OS, Linux , iOS and Android. You can check it out here : http://opencv.org/

Installing it can be a little confusing to some people. This is a complete guide which includes a step by step process on how to install it and run a simple code in Visual Studio 2012. 


You can watch the Video on YouTube and Follow the steps below:








Step 1: Downloading and installing


· Download OpenCV 3.0 at: http://opencv.org/downloads.html

· Download Visual studio 2012 at: http://www.microsoft.com/en-in/download/details.aspx?id=34673

· Install Visual studio 2012 and Log in with your Microsoft account if you already have one or you can sign up and register. The software is available for FREE

· Click on Opencv 3.0 and Extract the files to a location






Step 2: Create a system variable:


· Variable name: OPENCV_BUILD

· Value: C:\opencv3\build

· Path: C:\opencv3\build\x86\vc12\bin






Step 3: Configuration


1. Open Visual Studio and create a Console Application

2. Right click on the file and click properties

3. Choose Configuration Manager and add x64 platform if your system is x64 (only if your system is x64)

4. At configuration field, choose all configurations

5. At Configuration Properties - C/C++ - Additional Include Directories, add opencv include folders


Additional Include Directories:


· C:\opencv3\build\include


· C:\opencv3\build\include\opencv


· C:\opencv3\build\include\opencv2


Note: opencv3 is the folder in which I extracted the files (Check your folder name and folder location)









6. At Configuration Properties - Linker- Additional Library Directories, add opencv library folder


Additional Library Directories:

C:\opencv3\build\x86\vc12\lib



7. At configuration field, choose Debug mode


8. At Configuration Properties - Linker- Additional dependencies- add dependence libraries


Additional libraries


opencv_ts300.lib


opencv_ts300d.lib


opencv_world300.lib


opencv_world300d.lib


Note: These libraries are in the folder- C:\opencv3\build\x86\vc12\lib



9. At configuration field, choose Release mode


10. At Configuration Properties -Linker - Additional dependencies - add dependence libraries


Additional libraries


opencv_ts300.lib


opencv_ts300d.lib


opencv_world300.lib


opencv_world300d.lib


Note: These libraries are in the folder- C:\opencv3\build\x86\vc12\lib




Step 4: Build and Debug


· I have given a sample code.


· Copy -paste it and build it. And debug.




Note: In case there is an error like the '.Dll' file is missing,  Go to Environmental variables and check the path again and restart your computer.

It should work. 


If you want to use extra features available in the contrib_module , then you'll need to build the extra modules from source using cmake. I'll be writing another post showing how to do that.  
If  this was helpful please subscribe and If you have any questions feel free to comment or you can mail me



37 comments:

  1. ' opencv_world300.dll ' is missing!! how to...? Thnks..(y)

    ReplyDelete
    Replies
    1. Read the post properly.
      Check your environment variable path again and put the 'bin' folder as your path.
      And tell me if it works

      Delete
  2. I've reinstalled two of them Opencv 'n visual studio 2012, the result is good enough, but unfortunately
    ----------------------------------------------------------------------
    Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
    Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
    Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
    etc........
    Plz, help me:-)! Thnks....

    ReplyDelete
  3. If you're getting results, I'd suggest you ignore those messages.
    Take a look at this:
    http://stackoverflow.com/questions/15937707/error-message-cannot-find-or-open-the-pdb-file

    Also, you'll soon realize a lot of sample code from opencv documentation doesn't work and throws an exception

    for that i'd suggest you install opencv from source. It works really well.

    Read my other post for that.

    ReplyDelete
  4. yeah, got it!! I just succeed in installing opencv, but surprisingly come into the error list like this:

    ----------------
    'Project_This_Week.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
    'Project_This_Week.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.

    ReplyDelete
    Replies
    1. They are more like warnings and not errors. You can ignore them. Your project should work just fine.

      Delete
  5. it was some time ago, but wht makes it back to be error anymore this time? I've struggled to ignore them, but my project stay could not work fine!!
    Honestly, I'm really interested to this project this moment, that's why I do hope to be successful soonly, because after successful in this installing, I wannna try this by using camera as prototype in robot project ? thnks... (Y)

    ReplyDelete
  6. yeah, well done! Thnks your help....(Y)(Y)

    ReplyDelete
  7. so, could you tell me wht's the wiring + coding of the 'opencv arduino robot using mini webcam project'? waiting for the sending:-)
    see you ! Thnks....(y)

    ReplyDelete
  8. Haha you've got to do that on your own man. Although if you need help with anything specific, tell me.

    ReplyDelete
  9. well... so, could you tell me sample code of object tracking!

    ReplyDelete
  10. Google Kyle Hounslow. He's made a tutorial for object tracking using contours and sequential images,

    Also here's another one for object detection and tracking using opencv and arduino for servo motor control.
    http://www.instructables.com/id/OBJECT-DETECTION-AND-TRACKING-USING-OPENCV-VISUAL-/

    ReplyDelete
  11. I kept on getting the same error: "MSVCP120.dll is missing" any help?

    ReplyDelete
  12. Download and install Visual C++ Re distributable packages VS 2013. Here's the link:
    http://www.microsoft.com/en-gb/download/details.aspx?id=40784

    Restart your computer and build.It should work. If it doesn't, try again for VS 2012

    ReplyDelete
  13. i cant use detectMultiscale method, im having an issue with vector.

    Getting access violation reading location error, do you know something about it?

    ReplyDelete
  14. i have this message, what's the solution please ?
    ______________
    LINK : fatal error LNK1104: cannot open file 'gdi32.lib'
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. What is this error ?

    Unhandled exception at 0x0FE250B2 (opencv_world300.dll) in teste30.exe: 0xC0000005: Access violation reading location 0x00138000.

    ReplyDelete
    Replies
    1. Read this:
      http://audhootchavancv.blogspot.in/2015/08/how-to-install-opencv-30-and.html

      And then try again.

      Delete
    2. This comment has been removed by the author.

      Delete
  17. LNK1104: cannot opencv file 'opencv_world300d.lib'. I am getting this error boss

    ReplyDelete
    Replies
    1. Check your additional libraries and system variable once again. Restart your system and try.

      Delete
    2. I had the same error. I have checked the variables and already restarted, but the error is still there. Any other ideas?

      Delete
  18. Hey, I've done everything you noted in.
    I try to run the code you wrote down, and I get the following error
    "Unhandled exception at 0x000007FEE02B8B00 (msvcr120.dll) in ConsoleApplication4.exe: 0xC000001D: Illegal Instruction."

    I will be happy to help me solve the problem.

    Details: Windows 7, 64 bit Opencv-3.0.0 Visual studio 2012

    ReplyDelete
    Replies
    1. In my case, I search 'msvcr120.dll' in my Computer via search box, then I copy it and paste to windows\system32, that's all Ok!
      good luck!

      Delete
  19. i just got this
    'C:\Windows\System32\opencv_world300.dll'. Cannot find or open the PDB file.
    how to fix it? waiting for your answer

    ReplyDelete
    Replies
    1. check the lib folder for dll files. Add the files present in the folder!

      Delete
  20. Error 1 error LNK2019: unresolved external symbol cvReleaseImage referenced in function main C:\Users\Shahid\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Source.obj ConsoleApplication1
    ?????

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. In step2:
    Path: C:\opencv3\build\x86\vc12\bin
    shouldnt be there "\lib" instead "\bin " at the and ?
    Because i see there only lib or staticlib folders.

    I get opencv_world300.dll missing when run debugging or wanna run exe. I checket system variables and also visual studio setup. Any help ?

    ReplyDelete
  23. Lot of Thanks for your tutorial and videos!
    I was wondering if you would also help me out to get the "python" installed. Since I am a final year B.Tech student working in C++ and python Project for face recognition, and while generating Opencv via "Cmake", i dont have python, so cannot generate for this. Please help me out. If that "python27 & python34" of your "C" would be in my computer too then I could progress. Thanks

    ReplyDelete
  24. what should I do if it displays "THIS PROJECT IS OUT OF DATE" while builing the program.Please help me.Thanks in advance

    ReplyDelete
  25. Answer me as soon as possible.Thank you.and also i have got an error that "cannot open include file :highgui.h :No such file or directory

    ReplyDelete