zoukankan      html  css  js  c++  java
  • 角点检测

    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()
  • 相关阅读:
    java多线程之系列目录
    RecyclerView的源码分析
    ConCurrentHashMap在1.7和1.8区别
    插件化之细节
    组件化之开发细节
    组件化之开发总结
    线程之volatile基本内容
    线程之Synchronized基本内容
    设计模式之动态代理模式原理介绍
    操作系统之内存映射
  • 原文地址:https://www.cnblogs.com/hanker99/p/14483859.html
Copyright © 2011-2022 走看看