How to start learning opencv?

Source: Internet
Author: User

What is opencv? I believe that everyone who is engaged in Machine Vision knows it. However, many machine vision friends love and hate him. Love it because it is free. If you can master it and apply it to your machine vision project, you can still reduce the project cost to a certain extent. Hate it because it is not very good at learning. The reasons are as follows:
1. There are too few Chinese books on opencv in China. There are only two books, and the 1.1 version is still in use. It is too different from the latest version 2.4.3, it takes some time and effort to transition to the latest version.
2. Directly learn the higher version, but there is no corresponding tutorial for reference. You can directly read the help documentation in the English version. It is very difficult for friends who are not good at English.
3. Even if you can use English, it is estimated that some people do not have a good way to learn opencv efficiently, resulting in poor learning performance.
To help those who want to learn opencv but cannot do it, I would like to share some of my self-taught opencv experience and hope to help those who need it. Friends who have mastered good learning methods and have mastered opencv to a certain extent do not want to speak out.
1. download the latest version of opencv. The URL is as follows. After the download is complete, decompress the package to the corresponding directory. Decompress the package to D: \ Program Files \ opencv2.4.3.
2. Some Articles mentioned that using cmake to generate the following examples of opencv into a Visual Studio project, which I did not do here. Example. Here we will first describe several important directories under the opencv directory (see the attachment ):
Doc directory: contains the help documentation of opencv. Among them, opencv2refman.pdf is mainly used to describe various types and functions of opencv. Opencv_tutorials.pdf is a brief description of the teaching examples in the following teaching code directory. Opencv_cheatsheet.pdf is a collection of the most common opencv classes and functions. These three PDF documents are of the greatest help to scholars.
Samples \ CPP \ tutorial_code Directory: contains the basic teaching code. Echo the original opencv_tutorials.pdf file to form a complete self-learning system.
Build Directory: contains all types of dynamic libraries, static libraries, and header files required for compilation, debugging, and release.
Because opencv2.4.3 only supports Visual Studio 2008 and later versions, I will use Visual Studio 2008 as an example to explain how to run the example.
1. Add environment variables: see the image. Here, I add the following directory TO THE PATH environment variable: D: \ Program Files \ opencv2.4.3 \ build \ x86 \ vc9 \ bin. Remember to add points after the previous directory.
2. Include the header file directory in Visual Studio: see the picture in the attachment. You have used a red rectangle to identify how to operate the file.
3. Include the library file directory in Visual Studio: see the image in the attachment. You have used a red rectangle to identify how to operate the file.
4. Create a New Visual Studio VC Win32 console application project. Here I select a project with a precompiled header to save the effort of adding a CPP file.
5. Code creation: Here I select the samples \ CPP \ tutorial_code \ imgproc \ morphology_2.cpp file. Add the include directory first, as shown below (all examples can be added as follows ):
# Include <opencv2/opencv. HPP>
# Include <stdio. h>
Then copy the code, see the attachment:
6. Compile a file: it is essential to include a static library. The library to be added (the difference between the debug version and the release version is that a d logo is added after the file name) is as follows:
Debug
Opencv_calib3d243d.lib
Opencv_contrib243d.lib
Opencv_core243d.lib
Opencv_features2d243d.lib
Opencv_flann243d.lib
Opencv_gpu243d.lib
Opencv_haartraining_engined.lib
Opencv_highgui243d.lib
Opencv_imgproc243d.lib
Opencv_legacy243d.lib
Opencv_ml243d.lib
Opencv_nonfree243d.lib
Opencv_objdetect243d.lib
Opencv_photo243d.lib
Opencv_stitching243d.lib
Opencv_ts243d.lib
Opencv_video243d.lib
Opencv_videostab243d.lib

Release Version
Opencv_calib3d243.lib
Opencv_contrib243.lib
Opencv_core243.lib
Opencv_features2d243.lib
Opencv_flann243.lib
Opencv_gpu243.lib
Opencv_haartraining_engine.lib
Opencv_highgui243.lib
Opencv_imgproc243.lib
Opencv_legacy243.lib
Opencv_ml243.lib
Opencv_nonfree243.lib
Opencv_objdetect243.lib
Opencv_photo243.lib
Opencv_stitching243.lib
Opencv_ts243.lib
Opencv_video243.lib
Opencv_videostab243.lib
For more information about how to add a ram user, see the attachment.
7. Character Set setting: if the following error occurs during compilation:
The reason why parameter 1 cannot be converted from "_ tchar *" to "const STD: string &" is as follows: it cannot be converted from "_ tchar *" to "const STD: string ". Set the character set to "use multi-Byte Character Set". For the setting method, see attachment.
8. Specify the post-command parameters: see the attachment for the method. In this way, you do not need to enter parameters in the Windows command line to facilitate debugging, but note that the image must be placed in the project directory you have created (and. CPP and. H files in the same directory ). Otherwise, the corresponding path must be added. If there are more than one parameter, separate them with spaces.
9. All parameter settings are supported. start compiling and running.

If Visual Studio has no problem, follow the steps above and each example can run normally.
To learn opencv 2.4.3, do not rush into coding. You should first run its code to see what the result is. Xianzhi describes the running results, then reversely derives the programming ideas, finally looks at the code, analyzes the code, and clarifies the functions and functions of every opencv class and function to form its own ideas, finally, let go of the original code and break the code into it based on your own ideas so that the code can be digested and absorbed.
Of course, the learning methods may not be the same for everyone. Maybe others have their own unique learning methods for opencv. If so, share it with you.
Finally, to learn opencv well and use opencv for Machine Vision projects, it is not enough to rely solely on the APIS provided by opencv. We also need to add some basic knowledge of Digital Image Processing and do not ask ourselves to write processing algorithms, however, the function and application scope of each opencv processing operator should be clear. Only in this way can we know what APIs should be used in specific applications.
I have learned a little about opencv 2.4.3 and I will share it with you. If you are a master of opencv, you are still excited about it. I am very pleased to be able to help new users.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.