Opencv learning notes (50) -- algorithm class introduction (CORE)

Source: Internet
Author: User

Article from: http://blog.csdn.net/yang_xian521/article/details/7533922

At the beginning, I learned about the new 2.4.0 and read the user manual. I am still a little disappointed. Many chapters are still the content of 2.3.1. The code in the document is also vulnerable. Here we will briefly introduce the new base class algorithm. I thought this part was a new module. After reading referencemanual, I realized that it was only a base class and integrated some relatively complex algorithms, such as the BM algorithm and other three-dimensional matching algorithms, foreground background Separation Algorithms, optical flow, and other modules are integrated. In-class member functions include get, set, writhe, read, getlist, and create. The first four parameters are used to read algorithm parameters from strings and XML files. Get is used. Set must note that the type corresponding to the parameter name must correspond to the data type, you must understand the consequences. With Algorithm: Write, sitf: wirte, surf: write, and Shenma can all be seen again. Getlist can obtain the algorithm types supported by algorithm. I tested getlist. Currently, the getlist algorithms include brief, dense, fast, CFIT, Harris, mser, ORB, sift, Star, and surf. They will be implemented in the future, in the manual, only the introduction of surf and sift is available. At least currently, I think only these two algorithms are supported. Create is a function used to create an algorithm. It is relatively simple to use. It should be noted that the features2d module of the new version has been greatly changed. Anyway, most of the remaining parts in the document are some public interfaces, for example, feature descriptor, descriptive subextraction, and feature matching. Only fast, mser, And Orb still appear in the backbone of the document (it is estimated that they will be migrated later). The previous Star, randomtree, and rtreeclassifer should be abandoned together, ML removal is required. The new modules of sift and surf are also included in the nonfree module. However, this new module is weak. Currently, only the sift and surf algorithms are available, it is estimated that other algorithms will be integrated in the future.

Next, I will practice the new version of the sift feature point detection algorithm based on an example in the document, and compare the method of sitf in the previous version. Let's feel the difference in the new structure.

 

# Include <opencv2/opencv. HPP> # include <opencv2/nonfree. HPP> # include <opencv2/nonfree/features2d. HPP> using namespace CV; void main () {mat image = imread ("chilch01.jpg"); MAT imagegray = imread ("chilch01.jpg", 0); MAT descriptors; vector <keypoint> keypoints; // The new version 2.4.0 method initmodule_nonfree (); PTR <feature2d> sift1 = algorithm: Create <feature2d> ("feature2d. sift "); sift1-> set (" contrastthreshold ", 0.01f); (* sift1) (imagegray, noarray (), keypoints, descriptors ); // 2.3.1 method // siftfeaturedetector sift2 (0.06f, 10.0); // sift2.detect (imagegray, keypoints); drawkeypoints (image, keypoints, image, scalar (, 0 )); imshow ("test", image); waitkey ();}

Note the initmodule _ <modulename> () function. This function must be used before create to dynamically create an algorithm. Otherwise, the create pointer is very wild. Everyone knows. To use the surf and sift algorithms, you must call inintmodule_nonfree (). To use the EM algorithm, you must first call initmodule_ml ().

In fact, in my opinion, this algorithm class is more important to provide a public interface for developers' algorithms. In the future, the algorithms developed by developers will be added to opencv, just follow the algorithm interface to do OK, so as to avoid the increasing number of algorithms in the future, and our opencv will become bloated.

It's easy to create your own algorithm classes now. Use the algorithm class as the base class, the algorithm parameters as the member variables, call the get function, and add algorithminfo * Info () to add const and algorithminfo variables to your own algorithm class, you can refer to the initialization of EM algorithm to see how to operate and add other functions. After that, you can use create to call your own functions. This is a brief introduction. Later, you will have the opportunity to create your own functions. I have a deep understanding of it and then I will share it with you in detail.

 

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.