Python OpenCV3 BF Algorithm

BF algorithm is the abbreviation of Brute Force algorithm.It belongs to common pattern maching algorithm.its method is to compare
摘要由CSDN通过智能技术生成

Foreword

Next i’ll show you how to use the BF algorithm in Python.Before that let’s look at what BF algorithm is.

What’s the BF Algorithm

BF algorithm is the abbreviation of Brute Force algorithm.It belongs to common pattern maching algorithm.its method is to compare two strings A and B one by one. If the first character of string A is equal to the first character of steing B ,it will continue to compare the second character of the string A and B ,otherwise compare the first character of string A with the second character of string B ,until get the final result.

Library

pip install opencv-python

Python code

import cv2

# 按照灰度图像的方式读入两幅图片
img1 = cv2.imread("./8.jpg", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("./9.jpg", cv2.IMREAD_GRAYSCALE)

# 创建ORB特征检测器和描述符
orb = cv2.ORB_create()
# 对两幅图像检测特征和描述符
keypoint1, descriptor1 = orb.detectAndCompute(img1, None)
keypoint2, descriptor2 = orb.detectAndCompute(img2, None)

# 获得一个暴力匹配器的对象
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# 利用匹配器 匹配两个描述符的相近成都
maches = bf.match(descriptor1, descriptor2)
# 按照相近程度 进行排序
maches = sorted(maches, key=lambda x: x.distance)
# 画出匹配项
img3 = cv2.drawMatches(img1, keypoint1, img2, keypoint2, maches[0:70], img2, flags=2)

cv2.imshow("BF", img3)
cv2.waitKey(0)
cv2.destroyAllWindows()

Display

在这里插入图片描述
With this algorithm, we can use one special part of a picture to match the corresponding prat in the another picture.
Next blog i’ll introduce another matching algorithm—KNN

KNN algorithm

占有欲让人误以为自己很痴情。最后喜欢变成了不甘, 深爱变成了心酸。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值