Install opencv3.4.1(or newer version) on windows
1. Double click on the opencv-3.4.2-vc14_vc15.exe and extract it to your favorite folder(pic_00)
2. Open the folder you extract(assume you extract it to /your_path/opencv_3_4_2). You will see a folder call "opencv" .
Create a new project by Qt Creator
4. Create a new project
6. Enter the path of the folder and name of the project.
8. You will see a page ask you to select your kits, kits is a tool QtCreator use to group different settings like device, compiler, Qt version etc.
10. If you see a screen like this, that means you are success.
11. Write codes to read an image by opencv
How to compile and link the opencv lib with the help of Qt Creator and qmake
Before you can execute the app, you will need to compile and link to the libraries of opencv. Let me show you how to do it. If you missed steps a and b, you will see a lot of error messages like Pic07 or Pic09 show.
12. Tell the compiler, where are the header files, this could be done by adding following command in the step_02.pro.
INCLUDEPATH += your_install_path_of_opencv/opencv/opencv_3_4_2/opencv/build/include
The compiler will tell you it can't locate the header files if you do not add this line(see Pic07).
If your INCLUDEPATH is correct, QtCreator should be able to find the headers and use the auto complete to help you type less words(Pic08).
13. Tell linker which libraries of the opencv it should link to by following command.
LIBS += your_install_path_of_opencv/opencv/opencv_3_4_2/opencv/build/x64/vc14/lib/opencv_world342.lib
Without this step, you will see the errors of "unresolved external symbols"(Pic08).
Click the icon surrounded by the red region and change it from debug to release. Why do we do that? Because
- Release mode is much more faster than debug mode in many cases
- The library we link to is build as release library, do not mixed debug and release libraries in your project unless you are asking for trouble
Execute the appAfter we compile and link the app, we already have the exe in the folder(in the folder show at Pic11).
We are almost done now, just few more steps the app could up and run.
13. Copy the dll opencv_world342.dll and opencv_ffmpeg342_64.dll(they place in /your_path/opencv/opencv_3_4_2/opencv/build/bin) into a new folder(we called it global_dll).
14. Add the path of this folder into system path. Without step 13 and 14, the exe wouldn't be able to find the dll when we execute the app, and you may see following error when you execute the app from command line(Pic12). I recommend you use the tool--Rapid environment editor(Pic13) to edit your path on windows.
They are easy, but they could be annoying at first. I hope this post could leverage your frustration. You can find the source codes located at github.