OpenCV + Python Harris角点检测

原图:



Harris角点检测:



# -*- coding: utf-8 -*-

import cv2
import numpy as np
filename = 'C:\\Users\\kai\\Pictures\\rock2.bmp'
# C:\\Users\\kai\\Pictures\\sample\\13.bmp
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
# 输入图像必须是float32,最后一个参数在0.04 到0.05 之间
dst = cv2.cornerHarris(gray,2,3,0.04)
#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst>0.01*dst.max()]=[0,0,255]
cv2.imshow('dst',img)
if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/wukai0909/article/details/77688866