Python+OpenCV:ORB: An efficient alternative to SIFT or SURF

82 篇文章 20 订阅

Python+OpenCV:ORB: An efficient alternative to SIFT or SURF

理论

As an OpenCV enthusiast, the most important thing about the ORB is that it came from "OpenCV Labs".

This algorithm was brought up by Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary R. Bradski in their paper ORB: An efficient alternative to SIFT or SURF in 2011.

As the title says, it is a good alternative to SIFT and SURF in computation cost, matching performance and mainly the patents.

Yes, SIFT and SURF are patented and you are supposed to pay them for its use. But ORB is not !!!

ORB is basically a fusion of FAST keypoint detector and BRIEF descriptor with many modifications to enhance the performance.

First it use FAST to find keypoints, then apply Harris corner measure to find top N points among them. It also use pyramid to produce multiscale-features.

But one problem is that, FAST doesn't compute the orientation. So what about rotation invariance? Authors came up with following modification.

It computes the intensity weighted centroid of the patch with located corner at center. The direction of the vector from this corner point to centroid gives the orientation.

To improve the rotation invariance, moments are computed with x and y which should be in a circular region of radius r, where r is the size of the patch.

Now for descriptors, ORB use BRIEF descriptors. But we have already seen that BRIEF performs poorly with rotation.

So what ORB does is to "steer" BRIEF according to the orientation of keypoints.

For any feature set of n binary tests at location (xi,yi), define a 2×n matrix, S which contains the coordinates of these pixels.

Then using the orientation of patch, θ, its rotation matrix is found and rotates the S to get steered(rotated) version Sθ.

ORB discretize the angle to increments of 2π/30 (12 degrees), and construct a lookup table of precomputed BRIEF patterns.

As long as the keypoint orientation θ is consistent across views, the correct set of points Sθ will be used to compute its descriptor.

BRIEF has an important property that each bit feature has a large variance and a mean near 0.5.

But once it is oriented along keypoint direction, it loses this property and become more distributed.

High variance makes a feature more discriminative, since it responds differentially to inputs.

Another desirable property is to have the tests uncorrelated, since then each test will contribute to the result.

To resolve all these, ORB runs a greedy search among all possible binary tests to find the ones that have both high variance and means close to 0.5, as well as being uncorrelated.

The result is called rBRIEF.

For descriptor matching, multi-probe LSH which improves on the traditional LSH, is used.

The paper says ORB is much faster than SURF and SIFT and ORB descriptor works better than SURF.

ORB is a good choice in low-power devices for panorama stitching etc.

ORB in OpenCV

####################################################################################################
# 图像ORB: An efficient alternative to SIFT or SURF
def lmc_cv_image_orb_detection():
    """
        函数功能: 图像ORB: An efficient alternative to SIFT or SURF。
    """

    stacking_images = []
    image_file_name = ['D:/99-Research/Python/Image/Butterfly01.jpg',
                       'D:/99-Research/Python/Image/Butterfly02.jpg',
                       'D:/99-Research/Python/Image/Butterfly03.jpg',
                       'D:/99-Research/Python/Image/Butterfly04.jpg']
    for i in range(len(image_file_name)):
        # 读取图像
        image = lmc_cv.imread(image_file_name[i])
        image = lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2RGB)
        result_image = image.copy()
        gray_image = lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2GRAY)

        # Initiate ORB detector
        orb = lmc_cv.ORB_create()

        # find the keypoints with ORB
        keypoints = orb.detect(gray_image, None)

        # compute the descriptors with ORB
        keypoints, descriptors = orb.compute(gray_image, keypoints)

        # draw only keypoints location,not size and orientation
        result_image = lmc_cv.drawKeypoints(result_image, keypoints, None, color=(0, 255, 0),
                                            flags=lmc_cv.DRAW_MATCHES_FLAGS_DEFAULT)

        # stacking images side-by-side
        stacking_image = np.hstack((image, result_image))
        stacking_images.append(stacking_image)

    # 显示图像
    for i in range(len(stacking_images)):
        pyplot.figure('ORB in OpenCV %d' % (i + 1))
        pyplot.subplot(1, 1, 1)
        pyplot.imshow(stacking_images[i], 'gray')
        pyplot.title('ORB in OpenCV')
        pyplot.xticks([])
        pyplot.yticks([])
    pyplot.show()

    # 根据用户输入保存图像
    if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
        # 销毁窗口
        pyplot.close('all')
    return

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值