# coding=utf-8 import cv2 import numpy as np filename = ‘pic5.png‘ #1.读入一个灰度图像 img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) cv2.imshow(‘gray‘,gray) #2.执行角点检测函数 gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) #函数 cv2.cornerHarris() 可以用来进行角点检测 #数据类型为 float32 的输入图像 # 2:角点检测中要考虑的领域大小 #3: Sobel 求导中使用的窗口大小 #Harris 角点检测方程中的自由参数,取值参数为 [0,04,0.06] dst = cv2.dilate(dst,None) #扩大标记角 img[dst>0.01*dst.max()] = [0,0,255] #阈值为一个最佳值,它可能会根据图像而变化。 cv2.imshow(‘dst‘,img) cv2.waitKey(0) cv2.destroyAllWindows()
# coding=utf-8 import cv2 import numpy as np from matplotlib import pyplot as plt #1.读入图像,灰度 filename = ‘pic5.png‘ filename2 = ‘woman.JPEG‘ img = cv2.imread(filename2) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #2.执行角点函数 cv2.goodFeaturesToTrack corners = cv2.goodFeaturesToTrack(gray,50,0.01,10) #50个最佳点 #0.01 角点的质量水平,0到 1 之间 # 返回的结果是 [[ 311., 250.]] 两层括号的数组。 corners = np.int0(corners) #3.在img标记角点 for i in corners: x,y = i.ravel() cv2.circle(img,(x,y),3,255,-1) plt.imshow(img) plt.show()
原文:http://www.cnblogs.com/venicid/p/7833660.html