Install OpenCV C++ on Windows with MinGW Compiler

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is safal welcome to another interesting session here at gold hiroku at kodaroku our mission is to make world-class computer science and engineering education accessible to millions of students especially in developing countries like india in our today's video we will be going over opencv installation for c plus plus with mingw compiler for creating opencv programs in c plus plus so in this video we will be learning how to install mingw 64-bit compiler for running c plus programs then we will be learning how to install opencv to create opencv programs in c plus plus then we will be learning how to install cma we require cma to basically link the opencv libraries with mingw compiler so as to run the opencv programs in c plus then finally we will be creating a basic opencv c plus plus program and running it with the help of c cmake and mingw compile our main objective to select this path is to not depend on any ide like visual studio and be able to write our code in any text editor like sublime or notepad plus plus and be able to simply run it with command prompt also this approach for windows is more similar to what you would do on a linux or mac so let's start with the video [Music] for installing the mingw 64-bit compiler you can find the link in the description once you will open that link the setup for mingw 64-bit compiler will automatically start downloading here's a small note even if you have the mingw 32-bit compiler you would still need to download and install this compiler because this supports the posix thread which is necessary for running opencv programs in c plus plus in the 32-bit compiler if you try to run opencv programs you might encounter the mutex error so go ahead and download this setup now once you have downloaded the setup for the compiler you just need to install the compiler now now once installing the mingw compiler make sure that your threads is selected as posix and your architecture should be x86 64 and then click on next now here you can give the directory wherever you want to install this folder so i'll be installing in this directory only so i have selected this directory now go ahead and click on next and let us meet after this installation is over now once the compiler is successfully installed you just need to open this folder you'll find this mingw 64 folder once it is installed just open this folder again open this folder and this one go to pin and copy this path now you need to add this path to your environment variables to basically run the mingw compiler so just go ahead and on the search bar type environment variable now once this is open go to environment variables in this you will find the system variables here go to path click on new and paste the path of the binary folder of mingw compiler that you have copied so paste it here and let's do okay now to check whether mingw compiler is successfully installed or not you just open the command prompt type in command prompt and here you need to type g plus plus version so once you type in this command you'll get this version of the mingw c plus plus compiler and if the shows then you have successfully installed the compiler in your pc now once you have installed the mingw compiler now we will install opencv so open google and just go to opencv.org open this once you reach this page you need to go to library releases here you can find different versions of opencv you can go ahead and download whichever you want i will be downloading this 3.4.13 version so click once you open this page it will automatically start downloading so let us meet after this is completely downloaded once downloaded you will get this opencv self extractable file so just go ahead and double click on it here you can provide the directory wherever you want to extract this file so just select the directory and click on extract this will start extracting the opencv once extracted you will get this opencv file and now you would need to download the pre-pre-built library files for mingw compiler from the link in the description because by default opencv only provides pre-built libraries for visual studio compiler in windows so go ahead and download that file now once you have downloaded the file from the link in the description uh just go ahead and extract it so you can get the directory wherever you want to extract and just go ahead and extract now once extracted you will get this file just open this opencv mingw build file and go to x64 and just copy this mingw folder go back go to the folder wherever you have installed the opencv and open the opencv folder here go to build go to x64 and here you need to copy the mingw file that we have copied from the zip file so just copy it here once you have successfully copied this file just open this mingw folder go to pin copy this path you would again need to paste this path in your environment variables so just go ahead and in the start search environment variables once this is open go to environment variables go to path and a create new and paste this bin path here now you would also need to go to the slip path and you would also need to paste it in the environment variable so again open the environment variables go to path create new and paste it so once you have successfully pasted the bin and the lib path you have successfully installed the opencv for running it with mingw compiler now let us install cmake so for installing cmake just go to google and type cmake here you can go to the first link that comes up then go to download and here you will need to download this windows x64 installer so just go ahead and click on this link and it will start downloading cmake now once you have downloaded this cmake setup you can just go ahead and double click on it then you can just click on next and then go ahead and do the installation for cmake and let us meet after this is installed now once you would have installed the cmake you'll get this cmake folder just open it here go to pin and just copy this path and again you would have to add this to your environment variables so go ahead search for environment variables once this is open go to environment variables go to path and again copy create new and copy the bin path here just okay so now you have successfully installed cma again if you want to check that if the installation was correct or not you can just go to your command prompt and just type c make version and this will show you the version of c made this means that you have successfully installed cmake we have installed all the dependencies we can create the program for running opencv in c plus i will be creating a very basic program to show an image using opencv so let us create a new folder here and i'm going to name it opencv cpp now in this folder i'm going to create two files one would be our cpp file which would contain our program and the other would be cmakelists.txt file so let's create our program now i will be using atom text editor to create the program you can use whichever editor you want to so i'll be creating a new file let's save this file in the new folder that we have created yeah okay so let us name it as opencv hello world dot cpp so first we will import the necessary libraries now once we have imported the necessary libraries now we would need the path where the image is stored so i have copied the path of the image here once i have the path of the image i can use the i am read function of opencv to read the image now we are going to store the image in matte data type which is present in opencv we are going to use i am read function in which we provide the path of the image now check that if the image is read correctly or not we can just say that if the image is not correctly read we can say not hit the image and return from here otherwise if the image is correctly red we can use the i am show function to display the image all right so now we have created the complete program let us build the cmakelist.txt file now make sure that you name your cmake list file as this only and keep in mind the casing of the letters now initially in this file we need to provide what should be the minimum version of c make sure since i was using the three point two version of cma i have written 3.0 if you are using a lower version than 3.0 then you should change it accordingly then we are going to name our project open cv cpp now since we are using opencv so we would need to include the opencv package in this file we can say find package open eevee acquired then we would include the opencv directories then we would need to create a an executable file that will be used to run our program so we can write add executable let us name our executable file as display image and we have named our cp file as open cv hello world dot cpp now what we need to do is we need to link the opencv libraries with the compiler so we will write target link libraries and here we are going to provide the name of the executable file then link it with opencv libraries that's it that would be enough for running a program i'm going to save this now once you have created both these files just open command prompt in this folder and here you can say see make dot now cma dot command is needed to build the files and my hyphen g mingw make files command is needed to specify that we will be using the mingw compiler for running our program once you press enter this should be your output if you have followed all the steps properly and these files should be built in your folder where you created the cmake lists and the cpp file and make sure that this make file is present because this would be necessary for the further steps and then we can go to your command prompt and we can write mingw 32 make executable this will compile our program and link the opencv libraries with the compiler and finally build the executable file for us so let us check that everything is correct or not so here we are able to see the image and our program has run successfully so this was all about how to install cmake opencv and mingw compiler for running opencv program in c plus alright guys that's it for today's video i hope you learned something new today if you liked it please share it with your friends and also subscribe to our channel [Music] you
Info
Channel: Code Heroku
Views: 12,964
Rating: undefined out of 5
Keywords: opencv, mingw, mingw compiler tutorial, opencv installation, opencv installation in windows 10, machine learning, visual studios, without visual studio, cmake, cmake tutorial c++, c++ programming, C++, c++ opencv install, opencv cmake, opencv cmake windows, opencv c++ tutorial
Id: 03DAsDRmtvA
Channel Id: undefined
Length: 26min 15sec (1575 seconds)
Published: Sun May 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.