很简单,opencv把算法都封装好了.只有一个地方要注意,orb算法不具有尺度不变性,所以要把尺度缩放到统一大小.
1.提取orb算子
2.knn匹配特征算子
3.计算符合要求的特征算子数量
完整项目地址:https://github.com/liuzehao/orbmatching
'''
@Author: haoMax
@Github: https://github.com/liuzehao
@Blog: https://blog.csdn.net/liu506039293
@Date: 2019-10-22 17:42:53
@LastEditTime: 2019-10-23 10:20:08
@LastEditors: haoMax
@Description:
'''
import cv2
import os
# 自定义计算两个图片相似度函数
def img_similarity(img1_path, img2_path):
"""
:param img1_path: 图片1路径
:param img2_path: 图片2路径
:return: 图片相似度
"""
try:
# 读取图片
img1 = cv2.imread(img1_path, cv2.IMREAD_GRAYSCALE)#trainning picture
img2 = cv2.imread(img2_path, cv2.IMREAD_GRAYSCALE)
w ,h = img1.shape
w2,h2=img2.shape
img1=cv2.resize(img1,(h2,w2))