[300 OpenCV routines] 244. Brief feature description of feature detection

"300 OpenCV routines of youcans - general catalog"


[300 OpenCV routines of youcans] 244. Brief feature description of feature detection


6.7.1 Introduction to Algorithms

Binary Robust Independent Elementary Features (BRIEF), which constructs feature descriptors for detected feature points, is characterized by directly generating binary strings as feature descriptors, which is highly efficient.

SIFT uses 128-dimensional floating point numbers as feature descriptors, with a total of 512 bytes; SURF uses 64/128-dimensional feature descriptors, with a total of 256/512 bytes. Since there are often thousands of feature points, these feature description vectors take up a lot of memory, and the time required for feature point matching is also very long. These feature descriptors often have a lot of data redundancy and can be compressed or converted into binary strings to reduce memory and speed up matching.

BRIEF descriptor provides a feature description method that directly generates binary strings, which speeds up the creation of feature descriptors, and greatly reduces the memory footprint of feature descriptors and the time for feature matching. Therefore, the BRIEF operator is a fast way to compute and match feature point descriptors.

The idea of ​​the BRIEF descriptor is to select N point pairs in a certain pattern around the key point P, and combine the comparison results of the N point pairs as a descriptor. In order to maintain the consistency of point selection, a specially designed fixed mode is used in the project.

The implementation steps of BRIEF descriptor are:

(1) Perform Gaussian filtering on the image (σ=2) to eliminate the interference of noise;
(2) With the feature point as the center, select a square neighborhood window of s*s;
(3) According to a predetermined random algorithm, from the neighborhood Randomly select 2 points in the domain window to generate a point pair <x, y>, compare the size of the pixel value, and obtain a binary number 0/1;
(4) Repeat (3) several times (such as 256 times) to form a binary code, It is the BRIEF descriptor of the feature point.

insert image description here

Advantages and disadvantages of BRIEF descriptor:

(1) Advantages: Brief builds descriptors very quickly, and the generated binary descriptors are convenient for high-speed matching and easy to implement on hardware.

The speed of generating Brief is very fast. SURF takes 335ms to calculate the descriptors of 512 feature points, and Brief takes only 8.18ms; SURF descriptor matching takes 28.3ms, and Brief takes only 2.19ms.

(2) Disadvantages: It does not have rotation invariance, does not have scale invariance, and is more sensitive to noise.

In images with a small degree of rotation, the matching quality using the BRIEF feature descriptor is very high, and in most cases better than SIFT and SURF; but for images rotated more than 30°, the matching success rate of the BRIEF feature descriptor is extremely low, close to at 0.

The BRIEF algorithm does not involve feature point detection methods, and needs to be used in conjunction with feature point detection algorithms such as FAST, SURF, and CenSurE.


6.7.2 Brief class in OpenCV

OpenCV provides a wealth of feature detection algorithms, and inherits the cv::Feature2D class, using a unified definition and encapsulation.

OpenCV provides the cv::xfeatures2d::BriefDescriptorExtractor class to implement the Brief Detector method, inherits the cv::Feature2D class, and creates it through the create static method.

The constructor of the BriefDescriptorExtractor class is:

static Ptr< BriefDescriptorExtractor > 	create (int bytes=32, bool use_orientation=false)

In the Python language, OpenCV provides the interface function cv.xfeatures2d.BriefDescriptorExtractor.create() to instantiate the BriefDescriptorExtractor class.

cv.xfeatures2d.BriefDescriptorExtractor.create([, bytes=32, use_orientation=false]) → retval
cv.xfeatures2d.BriefDescriptorExtractor_create([, bytes=32, use_orientation=false]) → retval
brief.compute(image, keypoints[, descriptors=None]) → keypoints, descriptors

Parameter Description:

  • image: input image, single channel
  • bytes: the byte length of the descriptor, optional 16/32/64, default 32
  • use_orientation: Whether the sampling mode uses the keypoint orientation, optional, the default is false
  • keypoints : The detected keypoints, a special data structure
  • descriptors: descriptors of key points, Numpy array, shape (n, bytes)

Precautions:

  • The function cv.FastFeatureDetector.create() instantiates the FastFeatureDetector class and constructs a FastFeatureDetector object.
  • bytes is the byte length of the descriptor. Note that 1 byte is 8 bits, so bytes=16/32/64 means that the binary encoding length n used is 128/256/512.
  • descriptors is an array of BRIEF feature descriptors, with shape (n, bytes), where n is the number of keypoints, and bytes is the byte length of the descriptor 16/32/64.

Routine 14.26: Brief feature description for feature detection

    # 14.26 特征检测之 BRIEF 特征描述
    # # 读取基准图像
    img = cv.imread("../images/book01.jpg", flags=1)  # 基准图像
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)  # (425, 558)
    height, width = gray.shape[:2]
    print("shape of image: ", height, width)

    # SIFT 关键点检测 + SIFT 特征描述
    # sift = cv.xfeatures2d.SIFT_create()  # OpenCV 早期版本
    sift = cv.SIFT.create()  # sift 实例化对象
    kpSift = sift.detect(gray, None)  # 关键点检测,kp 为关键点信息(包括方向)
    print("shape of keypoints: ", len(kpSift))  # 775
    imgSift1 = cv.drawKeypoints(img, kpSift, None)  # 只绘制关键点位置
    imgSift2 = cv.drawKeypoints(img, kpSift, None, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)  # 绘制关键点大小和方向

    # SIFT 关键点检测 + BRIEF 特征描述
    brief = cv.xfeatures2d.BriefDescriptorExtractor_create()  # BRIEF 特征描述
    kpBrief, des = brief.compute(img, kpSift)  # 对 SIFT 检测的关键点,通过 BRIEF 计算描述子
    imgBrief1 = cv.drawKeypoints(img, kpBrief, None)
    imgBrief2 = cv.drawKeypoints(img, kpBrief, None, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    print(des.shape)

    # STAR 关键点检测 + BRIEF 特征描述
    star = cv.xfeatures2d.StarDetector_create()  # STAR 特征检测
    brief2 = cv.xfeatures2d.BriefDescriptorExtractor_create()  # BRIEF 特征描述
    kpStar = star.detect(img, None)  # STAR 特征检测
    kpBriefStar, des = brief.compute(img, kpStar)  # 通过 BRIEF 计算描述子
    imgBriefS1 = cv.drawKeypoints(img, kpBriefStar, None)
    imgBriefS2 = cv.drawKeypoints(img, kpBriefStar, None, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    print(des.shape)

    plt.figure(figsize=(10, 6))
    plt.subplot(231), plt.title("SIFT keypoints")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgSift1, cv.COLOR_BGR2RGB))
    plt.subplot(234), plt.title("SIFT scaled keypoints")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgSift2, cv.COLOR_BGR2RGB))
    plt.subplot(232), plt.title("SIFT & BRIEF keypoints")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgBrief1, cv.COLOR_BGR2RGB))
    plt.subplot(235), plt.title("SIFT & BRIEF scaled kps")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgBrief2, cv.COLOR_BGR2RGB))
    plt.subplot(233), plt.title("STAR & BRIEF keypoints")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgBriefS1, cv.COLOR_BGR2RGB))
    plt.subplot(236), plt.title("STAR & BRIEF scaled kps")
    plt.axis('off'), plt.imshow(cv.cvtColor(imgBriefS2, cv.COLOR_BGR2RGB))
    plt.tight_layout()
    plt.show()


insert image description here



Credits: Michael Calonder, Vincent Lepetit, Christoph Strecha, et al. “BRIEF: Binary Robust Independent Elementary Features.” In Computer Vision–ECCV 2010, pages 778–792. Springer , 2010 .

insert image description here

【End of this section】

Copyright statement:
youcans@xupt original work, reprint must mark the original link: (https://blog.csdn.net/youcans/article/details/127352928)
Copyright 2022 youcans, XUPT Crated
: 2022-10-16

240. Shi-Tomas corner detection in OpenCV
241. Scale-invariant feature transformation (SIFT)
242. Accelerated robust feature detection algorithm (SURF)
243. FAST algorithm for
feature detection 244. Brief feature description for feature detection

Guess you like

Origin blog.csdn.net/youcans/article/details/127352928