栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

基于python的orb关键点及其匹配

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于python的orb关键点及其匹配

前言

orb特征检测和二进制描述符算法采用了定向的FAST检测方法和旋转的BRIEF描述符。

代码
from skimage import transform as transform
from skimage.feature import (match_descriptors,ORB,plot_matches)
from skimage.color import rgb2gray
from skimage.io import imread
import matplotlib.pyplot as plt



if __name__ == '__main__':
    img1 = rgb2gray(imread('../images/me5.jpg'))
    img4 = transform.resize(rgb2gray(imread('../images/me6.jpg')),
                            img1.shape,anti_aliasing=True)
    
    descriptor_extractor = ORB(n_keypoints=200)

    descriptor_extractor.detect_and_extract(img1)
    keypoints1,descriptors1 = descriptor_extractor.keypoints,descriptor_extractor.descriptors

    descriptor_extractor.detect_and_extract(img4)
    keypoints4,descriptors4 = descriptor_extractor.keypoints,descriptor_extractor.descriptors

    print(len(keypoints1),len(keypoints4))

    matches14 = match_descriptors(descriptors1,descriptors4,cross_check=True)
    print(matches14.shape)
    # matches14 = matches14[5:10]

    pig,ax = plt.subplots(1,1,figsize=(15,15))
    plot_matches(ax,img1,img4,keypoints1,keypoints4,matches14)
    ax.axis('off'),ax.set_title('image1 vs image4',size=10)
    plt.show()

结果

基于opencv的orb特征匹配 代码
import matplotlib.pyplot as plt
import cv2


if __name__ == '__main__':
    img1 = cv2.imread('../images/books.png',0)
    img2 = cv2.imread('../images/book.png',0)

    orb = cv2.ORB_create()
    
    kp1,des1 = orb.detectAndCompute(img1,None)
    kp2,des2 = orb.detectAndCompute(img2,None)

    bf = cv2.BFMatcher(cv2.NORM_HAMMING,crossCheck=True)

    matches = bf.match(des1,des2)
    
    matches = sorted(matches,key=lambda x:x.distance)
    print(len(matches))

    # 画前20个匹配点
    img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:20],None,flags=2)
    plt.figure(figsize=(20,10)),plt.imshow(img3),plt.show()
结果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/892610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号