How To Configure OpenCV C++ projects in Windows Using CMake? | CMAKE | OpenCV | Visual Studio Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone let's see how to configure opencv uh using cmake in windows i'm going to use the pre-compiled opencv libraries so let's get on to opencv.org and from the releases you can get the binary file from here it is a self extracting zip file and i already have it here so as you can see you can extract it wherever you want but i prefer it to be in my c drive so after extracting the only thing you have to do [Music] for the opencv to be able to link after extracting the only thing you have to do is so i extracted it here so just head on here so here the built binary file will be here so visual studio the binary folder is here so the library is here so what we are going to do is just copy this path and add it to the system path so just search environment variable in your just copy this and paste in your environment variables so and just search environment variables and go to your path so in path click edit and create a new path so i just pasted it here actually and then the library path so copy this and paste it here paste it in the same but create new and paste so just make sure both are here yes so opencv build x64 vc15 bin and vc15 lib both are here so that's it for here that's it for now and let's open visual studio actually i am going to use visual studio code so [Music] let me create a new folder from scratch i'm going to do everything from scratch so i'm going to create an open folder i'm going to create a new folder here [Music] new folder open cv tube cmake okay just selecting this folder and before doing anything uh i have to show you something here in the extensions you must install c plus plus extension so i already installed it c make yes here this c make i already installed it and c make list auto completion will be so make sure to install cmake and cmake tools both because cmake will give you [Music] support when editing the cmake files and the cma tools is provided by microsoft to actually go over the system path and other cmake related things and [Music] basically it is the extension that helps reading the cmake lists text cmakelist.txt and generating the build files for you so make sure you install these two extensions and this c plus plus extension and that's it so let me go to the files and let me quickly create a cmakelist.txt i just created an empty folder named opencv tute cmake and from here just press ctrl shift and p and search c make configure so this will uh ask which compiler you are going to use so i'm going to use use the 64-bit compiler sorry i'm going to generate 64-bit uh so i'm going to use 64-bit binaries i'm going to generate 64-bit binary so i'm going to select this one so this will automatically generate a cmake list file so just create and here you have to enter the project name i'm going to keep it as opencv c make so it is going to be an executable so it will automatically generate a c make list for you and then uh main.cpp source file also so from here you just have to add your add your library there is opencv using find package so find package opencv pay attention to the upper and lower cases here because o is upper case and c and v are uppercase and then required so there is some bug in visual studio so you have to once it is created you have to click locate to locate this also so load so once you do that this is one time configuration that initially generates all the build files and yeah i'm going to allow intelligence for this project and that's it so opencv is added and we have to link the executable with the opencv binaries so target link libraries this is opencv cmake is going to be linked with opencv libs directory yeah so this is pretty much it then let's dive into the code so let me actually get rid of this and yeah i found why uh intelligence is not picking up the opencv header files is because we have to add this opencv include directories so find the opencv package and include the directories and create the executable here and then link that executable with the opencv libraries so that's it so now once it is generated we can go back here and it should it should find opencv yes it it date found opencv so opencv and opencv.hbp so now let me quickly write a program to read a single image file and then display it so i can read and we are going to give a file name here so let me actually pull a file to here rename it to tiger so okay let's see the program here uh this is a simple simple example i wrote here it's just going to show an image and whenever we give a key input the window will close and the program will terminate that's it ah let's see a quick recap here we actually [Music] let me give a quick recap here we used the visual studio code to generate the cmake lists automatically and these two lines are for [Music] opencv to be found from the system path and the include directories is the directory where the header files are located and this target link library is to link the dll files opencv dll files with the executable that we generate so well this is a simple program where i created an image variable and stored this image here and then just displayed it using am show and then this weight key will wait for a keep stroke and once we give any input and it will just terminate the program so let me build this and run that's it if i press any key it will close and you can anything you want with opencv in this code so thank you for watching and subscribe for more videos like this thank you
Info
Channel: Makeitnow
Views: 22,679
Rating: undefined out of 5
Keywords: opencv, OpenCV, CMAKE, cmake, windows, opencv windows, opencv c++, c++, C++, visual studio code
Id: MOOCpt4lDPw
Channel Id: undefined
Length: 13min 12sec (792 seconds)
Published: Sat Jan 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.