|
- import cv2 as cv
- import numpy as np
-
- img = cv.imread('10069.jpg')
- img = cv.resize(img, (800, 800))
-
- '''
- # 用默认值初始化FAST对象
- fast = cv.FastFeatureDetector_create()
-
- # 寻找并绘制关键点
- kp = fast.detect(img,None)
- img2 = cv.drawKeypoints(img, kp, None, color=(255,0,0))
-
- # 打印所有默认参数
- print( "Threshold: {}".format(fast.getThreshold()) )
- print( "nonmaxSuppression:{}".format(fast.getNonmaxSuppression()) )
- print( "neighborhood: {}".format(fast.getType()) )
- print( "Total Keypoints with nonmaxSuppression: {}".format(len(kp)) )
- cv.imshow('fast_true', img2)
-
- # 关闭非极大抑制
- fast.setNonmaxSuppression(0)
- kp = fast.detect(img,None)
- print( "Total Keypoints without nonmaxSuppression: {}".format(len(kp)) )
- img3 = cv.drawKeypoints(img, kp, None, color=(255,0,0))
- cv.imshow('fast_false', img2)
-
- cv.waitKey(0)
- cv.destroyAllWindows()
- '''
-
- '''
- gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
- gray = np.float32(gray)
- dst = cv.cornerHarris(gray,2,3,0.04)
- #result用于标记角点,并不重要
- dst = cv.dilate(dst,None)
- #最佳值的阈值,它可能因图像而异。
- img[dst>0.01*dst.max()]=[0,0,255]
- cv.imshow('dst',img)
- '''
-
- gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
- corners = cv.goodFeaturesToTrack(gray,25,0.01,10)
- corners = np.int0(corners)
- for i in corners:
- x,y = i.ravel()
- cv.circle(img,(x,y),3,255,-1)
- cv.imshow('dst',img)
-
- cv.waitKey(0)
- cv.destroyAllWindows()
|