OpenCV(45):ORB feature points

1. Composition of feature points

Feature points consist of key points and descriptors :

  • Keypoints are detected location coordinates with significant changes in the image.
  • A descriptor is a vector or feature vector used to represent the characteristics of a local area around a key point.

2. ORB feature point principle

ORB feature points are composed of key points FAST corner points and descriptors BRIEF .

2.1 Algorithm for extracting FAST corner points

      The idea of ​​​​the FAST algorithm is to quickly detect corner points by comparing pixels with large differences (too bright or too dark) relative to the center pixel. Proceed as follows:

  • Select a certain pixel as the center point P, and its pixel value is I
  • Set the pixel value for determining FAST corner points, for example =20%*1
  • Compare the pixel value of the center point with the pixel value of all pixels on the circle with a radius of 3. If there are consecutive N pixels with pixel values ​​greater than or less than the pixel value, the pixel point p is a corner point.
  • Traverse each pixel in the image and repeat the above steps

2.2 Direction allocation:

       Assign a main direction to each detected corner point. In order to achieve rotation invariance, the grayscale centroid algorithm (Intensity Centroid) is used. Calculate the grayscale centroid of the image near the feature point. The so-called centroid refers to the center of the grayscale value of the image block as the weight. The calculation method is as follows:

2.3 Algorithm for generating BRIEF descriptors

       The idea of ​​the BRIEF descriptor generation algorithm is to compare the grayscale difference between two pixel pairs and encode the comparison result into a binary string. The steps to specifically describe the BRIEF descriptor are as follows:

  • Select a fixed set of sampling point pairs
  • Calculate the pixel difference value of the sample point pair
  • For the pixel difference value of each pair of sampling points, compare it with the threshold to obtain a binary comparison result. Usually, if the gray value of the first pixel is greater than the gray value of the second pixel, the binary bit at the corresponding position is set to 1; otherwise, it is set to 0.
  • Combine all binary comparison results into a binary string as a BRIEF descriptor.

2.4 Descriptor matching

        For two feature points in the image, the distance or similarity measure between the descriptors is used for matching. The most common method is to calculate the Hamming Distance or Euclidean distance between descriptors, and determine whether the match is successful based on a preset threshold. Fast matching algorithms such as KD trees or approximate nearest neighbor algorithms can also be used to speed up the matching process.

3.ORB feature point extraction function create()

static Ptr<ORB> cV::ORB::create ( int   nfeatures = 500,

float    scaleFactor = 1.2f,

int          nlevels = 8,

int          edgeThreshold = 31,

int           firstLevel = 0,

int          WTA K = 2,

ORB::ScoreType scoreType = ORB: :HARRIS_SCORE,

int         patchSize = 31,

int         fastThreshold = 20

)

  • nfeatures: The number of detected ORB feature points
  • scaleFactor: the ratio by which the pyramid size is reduced
  • nlevels: number of pyramid levels
  • edgeThreshold: edge threshold
  • firstLevel: Put the original image into the level of the pyramid
  • WTA K: The number of pixels needed to generate each descriptor
  • scoreType: key point evaluation method when detecting key points
  • patchSize: the size of the neighborhood around the key point when generating the descriptor
  • fastThreshold: The reading value of the pixel value difference when calculating FAST corner points

4. Sample code

void ORB_f(Mat mat){
    //创建ORB特征点类变量
    Ptr<ORB> orb=ORB::create(500,//特征点数目
                             1.2f,//金字塔层级之间的缩放比例
                             8,//金字塔图像层级系数
                             31,//边缘阈值
                             0,//原图在金字塔中的层数
                             2,//生成描述子时需要用的像素点数目
                             ORB::HARRIS_SCORE,//使用Harris方法评价特征点
                             31,//生成描述子时关键点周围邻域的尺寸
                             20//计算FAST角点时像素值差值的阈值
            );
    //计算ORB关键点
    vector<KeyPoint> Keypoints;
    orb->detect(mat,Keypoints);//确定关键点

    //计算ORB描述子
    Mat descriptions;
    orb->compute(mat,Keypoints,descriptions);//计算描述子

    //绘制特征点
    Mat mat2;
    mat.copyTo(mat2);
    //绘制不含角度和大小的结果
    drawKeypoints(mat,Keypoints,mat,Scalar(255,255,255,255));
    //绘制不含角度和大小的结果
    drawKeypoints(mat,Keypoints,mat2,Scalar(255,255,255,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    //显示结果
    imwrite("/sdcard/DCIM/mat.png",mat);
    imwrite("/sdcard/DCIM/mat2.png",mat2);

}

Show results:

      (Plot results without angle and size) (Plot results with angle and size)

Guess you like

Origin blog.csdn.net/weixin_63357306/article/details/132902974