• 角点检测


    import cv2 as cv
    import numpy as np

    filename = 'JG.png'
    img = cv.imread(filename)
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    _, img2 = cv.threshold(gray, 0, 0xff, cv.THRESH_OTSU)
    # cv.imshow('ordinary', img2)
    # FAST角点检测算法:
    fast = cv.FastFeatureDetector_create(threshold=40, nonmaxSuppression=True, type=cv.FAST_FEATURE_DETECTOR_TYPE_9_16)
    kp = fast.detect(img, None)
    cv.drawKeypoints(img, kp, img, color=(255, 255, 255))

    # SURF角点检测
    minHessian = 1000
    detector = cv.xfeatures2d.SURF_create(minHessian)
    descriptor = cv.xfeatures2d.SURF_create()
    matcher1 = cv.DescriptorMatcher_create('BruteForce')
    # 检测特征点
    keyPoint1 = detector.detect(img)
    keyPoint2 = detector.detect(img2)
    # 计算特征点对应描述子
    _, descriptor1 = descriptor.compute(img, keyPoint1)
    _, descriptor2 = descriptor.compute(img2, keyPoint2)
    # 描述子匹配
    matches = matcher1.match(descriptor1, descriptor2)
    img_matches = np.empty(img2.shape)
    img_matches1 = cv.drawMatches(img, keyPoint1, img2, keyPoint2, matches, img_matches)
    cv.imshow('img_matches', img_matches1)
    cv.waitKey()
    print('keyPoint1.size = ', len(keyPoint1))
    print('keyPoint2.size = ', len(keyPoint2))

    cv.waitKey()
    cv.destroyAllWindows()
  • 相关阅读:
    使用pipenv管理虚拟环境
    使用cookiecutter创建django项目
    Django中ModelViewSet的应用
    Redis添加历史浏览记录
    Django中配置用Redis做缓存和session
    点击即复制
    PostGreSQL数据库安装配置说明
    IntelliJ IDEA 2017.1.4 x64配置说明
    Struts2之2.5.10.1HelloWorld
    Apache Shiro系列(1)
  • 原文地址:https://www.cnblogs.com/hanker99/p/14483859.html
Copyright © 2020-2023  润新知