Part 4 - Adding opencv library to visual studio.
- First open Visual Studio 2015.
- Then go the file -> New -> Project
- Then go to Visual C++ -> Win32Console Application and press Ok.
- Then click Next.
- Then tick on Empty project & click Finish.
- After finishing above step you will see the following window.
- Then following window will display.
- Then you can test a sample program which are available in your opencv samples. Go to your opencv31 directory and go sources -> samples -> cpp -> tutorial code -> ImgProc and open Morphology_1.cpp with WordPad. Then copy this code and paste it to your project.
- As you can see there will be some errors in the code. The reason is we didn't include the opencv library to this project yet.
- To add the library, Right click on your project ( ConsoleApplication4 in my case ) and go the Properties.
- Make sure Configuration is debug and Platform is set to x64. If not set those.
- If x64 option is not available in platform, click configuration manager -> Platform -> New. Then select x64 and click Ok.
- Then go to C/C++ -> General -> Additional Include Directories -> Edit and add following three directories then press Ok.
- opencv31 -> build -> include
- opencv31 -> build -> include -> opencv
- opencv31 -> build -> include -> opencv2
- Then follow Linker -> General -> Additional Library Directories -> Edit to add following directory.
- opencv31 -> build -> x64 -> vc14 -> lib
- After that follow Linker -> Input -> Additional Dependencies -> Edit and type opencv_world310d.lib. Then click Ok.
- And also select x64 as following window.
- Noew you can see there's no errors shown in your code. It means that you successfully add the opencv library.
- Before run the project go to your project properties ( ConsoleApplication4 ) -> Debugging -> Command Argument and type "directory of image/imagename.jpg".
- In my case I give C:\Users\hashan\Desktop\hashan.jpg.
- Now you may run the project by Debug -> Start Without Debugging or simply press ctrl + F5.
- Now you can observe the output. This is the output I observed.
You can see the video demo below. It's describe everything.
If you cannot see this video go this link.
- Thank you very much for reading this tutorial. If you have problems regarding this tutorial feel free to make a comment below or contact us by sending message through our facebook page or by sending email to this address progtpoint@gmail.com.
- Follow us on facebook and twitter also subcribe us youtube.
thank you for this tutorial
ReplyDeletebut i have a problemes when I Debug my programme
(1>------ Début de la génération : Projet : opencv_test, Configuration : Debug x64 ------
1> teste.cpp
1>c:\microsoft visual studio 14.0\vc\include\crtdefs.h(10): fatal error C1083: Impossible d'ouvrir le fichier include : 'corecrt.h' : No such file or directory
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ========== )