Learning the learning notes series of OpenCV-Environment configuration 2, opencv learning notes
To learn OpenCV well, you must first know how to configure the environment. Take your own configuration environment as an example. The steps are as follows.
Step 1 download and decompress the OpenCV source code
Although many third-party websites and some learning forums provide OpenCV source code downloads, we recommend you download them on the official website to avoid a lot of trouble! (Virus? Trojan? You know !)
The official website is as follows:
Http://opencv.org/downloads.html
You can find the latest OpenCV source code on this address interface. I am using version 2.4.9 updated on version (currently the latest). Select the source code version based on your system.
Because my computer is WIN7x64Bit, select the "OpenCV for Windows" link to download it.
After downloading, you can see the code extraction program of this exe.
Double-click the extract program and select the extract directory. The G disk is selected here.
Click the "Extract" button, and the program will automatically Extract the OpenCV source code to the "opencv" Directory of G (this directory is generated by itself, you do not need to write it in the release program !).
Under the "G: \ opencv" directory, we can see two folders: "build" and "source.
Step 2 configure the OpenCV system variable path
After installing the source code of OpenCV, you must configure the system path of OpenCV.
Right-click "computer" in the Start menu and choose "properties". On the left side of the page displayed, click "Advanced System settings". Then, select the "advanced" tab in the "System Properties" dialog box.
Click "environment variable ".
In the "System variables" area under the displayed "environment variables" dialog box, locate the "Path" option, and double-click
In the displayed "Edit System variables" dialog box, add a variable in the "variable value" Column (note that adding is separated by semicolons at the end of this column) "G: \ opencv \ build \ x86 \ vc10 \ bin;" and "G: \ opencv \ build \ x64 \ vc10 \ bin;" (for 32-bit systems, you don't need to use this one ).
So far, the path of the system variables of OpenCV has been configured.
Step 3 configure the VS2010 Environment
Open Visual Studio 2010, create a new Visual C ++ project, select "Win32 console application", and name "HelloOpenCV". Click "OK.
In the displayed "Win32 Application Wizard" dialog box, click "Next"
On the "Additional Options" Page, select "Empty Projects" and click "finish ".
On the "HelloOpenCV" project interface, click "View" in the menu bar, select "other window", and click "Property Manager ".
In the pop-up "Property Manager", find the "Debug | Win32" folder and double-click the "Microsoft. Cpp. Win32.user" option.
In the next "Microsoft. cpp. on the Win32.user property page, find the "VC ++ directory" option under "general attributes" and click "edit" in "include directory" on the right ".
In the "include directory" dialog box, create three include directory paths:
1. G: \ opencv \ build \ include
2. G: \ opencv \ build \ include \ opencv
3. G: \ opencv \ build \ include \ opencv2
Click "OK ".
Then, add the directory path of the OpenCV static library to the "library directory.
Whether it is a 64-bit system or not, you only need to add "G: \ opencv \ build \ x86 \ vc10 \ lib". You do not need to add "G: \ opencv \ build \ x64 \ vc10 \ lib "unless you use a 64-bit compiler.
Next, configure the dynamic link library.
On the Microsoft. Cpp. Win32.user attribute page, click "input options" in "linker", click the arrow, and select "edit ".
In the "add dependency" dialog box that appears, add the following path:
Opencv_ml249d.lib
Opencv_calib3d249d.lib
Opencv_contrib249d.lib
Opencv_core249d.lib
Opencv_features2d249d.lib
Opencv_flann249d.lib
Opencv_gpu249d.lib
Opencv_highgui249d.lib
Opencv_imgproc249d.lib
Opencv_legacy249d.lib
Opencv_objdetect249d.lib
Opencv_ts249d.lib
Opencv_video249d.lib
Opencv_nonfree249d.lib
Opencv_ocl249d.lib
Opencv_photo249d.lib
Opencv_stitching249d.lib
Opencv_superres249d.lib
Opencv_videostab249d.lib
Opencv_objdetect249.lib
Opencv_ts249.lib
Opencv_video249.lib
Opencv_nonfree249.lib
Opencv_ocl249.lib
Opencv_photo249.lib
Opencv_stitching249.lib
Opencv_superres249.lib
Opencv_videostab249.lib
Opencv_calib3d249.lib
Opencv_contrib249.lib
Opencv_core249.lib
Opencv_features2d249.lib
Opencv_flann249.lib
Opencv_gpu249.lib
Opencv_highgui249.lib
Opencv_imgproc249.lib
Opencv_legacy249.lib
Opencv_ml249.lib
Here, the blue is the library file in debug mode. It can be seen that the name is followed by a "d" (representing debug), and the red is the library file in release mode, do not contain the suffix "d.
Generally, we will write all the items with and without d here, because these public attributes will be inherited when all projects are created in the future, so that you do not need to configure them for each project in the future, saving time and effort.
Step 4 Engineering Test
After completing the above steps, we 'd better restart the system to make some of our configurations take effect to avoid the following test errors.
In solution Resource Manager of the "HelloOpenCV" project we created, right-click "source file" and add a new item.
In the "Add new project" dialog box, select and add a "C ++ file (. cpp)" file, name it "main", and click "add ".
Add the following code to the main. cpp file:
# Include <iostream> # include <opencv2/core. hpp> # include <opencv2/highgui. hpp> using namespace cv; int main () {// read an image Mat myImg = imread ("test.jpg "); // create a window named "HelloOpenCV" namedWindow ("HelloOpenCV"); // display the window imshow ("HelloOpenCV", myImg ); // wait 10 seconds before closing the waitKey (10000 );}
Upload test.jpg to the project file directory, compile the file, and click debug.
The effect is as follows:
So far, all configurations have been completed and the test has passed. Next, we can enjoy the various surprises that OpenCV brings to us.
Basic openCV problems (learning opencv Example 2)
CvCapture * capture = cvCreateFileCapture ();
In this case, you must give the variable in the settings. In the settings, you must give test. avi to argv [1] so that you can do this.
How to Learn opencv is more efficient? Opencv Instructors
From being recommended by the lab OpenCV to using programming for a week, I feel that learning this is the same as learning Most program tools, that is, learning it is actually a matter of practice.
1. First of all, it is a reference book. I recommend you a relatively basic one. I think it is very suitable for you to get started.
OpenCV tutorial-basics: Beihang Press
Many teachers and students of Beihang Virtual Reality lab are using opencv and have a lot of experience. This book is of good quality and easy to use. The code in the attached CD is highly reliable, and some directly implement some algorithms or problems.
2. Then the learning method. The learning of program tools is quite different from that of other courses. If you want to take the exam, you don't have to worry about this one. You just need to write a book based on the recommended textbooks of the exam subject, and then do a few exercises, a few exam sets, and answer questions. The score must be good. If you want to be able to use it, you must learn and use it.
3. Specific process:
We recommend that you first read the book to understand the framework and structure of OpenCV, and understand the usage and usage of OpenCV Based on the introduction or overview. Generally, the Environment configuration and tools to be downloaded are provided in the book. Please strictly follow the requirements in the book. It makes sense that VC ++ 6.0 is recommended in the book, because the VC version has a wide range of use bases, CSDN, PUDN and other forums have a lot of code support. Moreover, domestic and foreign teachers and students have rich experience in usage. I used VS 2008 to complete the process. I found that the environment variables and other configurations are far more complex than this one. In the future, I had to troubleshoot some inexplicable problems.
We recommend that you understand each part of the function according to the Section and run the example in the book correctly (the CD has code ). Then, modify and digest the functions to achieve integration. For example, if the book teaches you the image format of opencv, you need to focus on reading and writing image data, and then try to insert an algorithm to modify the image (such as simple flip and reverse colors ). This method ensures that you have thoroughly understood every example and can distinguish between key code and Common Code, so that you can use the Code together in the future. You don't need to know the implementation process of each function. You only need to know what the parameters of each function are, what the functions are, and what special requirements (such as image format, parameter memory allocation ). If you do not know, you can refer to the SDK instructions, or MSDN, or you can know it hundreds of times or write a simple program to test each function.
We recommend that you complete a small project by integrating the methods you know into a specific project. For example, you can perform face detection or pedestrian detection. These things have mature technologies, a large number of papers, and various implementation methods. You don't have to be intimidated by the numerous papers, absorb their excellent algorithm ideas, discard their dregs, and combine your own algorithms to complete the task. In this way, you can write your own thesis on this basis, write a demo program to support your thesis, and test your data through an experiment program. If you have completed these steps, you can say that you are getting started with opencv.
The above are my personal opinions, which are not persuasive. I just want to share them with students who like programming.