Python 官方文档:入门教程 => 点击学习
这篇文章主要介绍了python中Harris角点检测的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。1、基本思想选择在图像上任意方向的固定窗口进行滑动,如果灰度变化较
这篇文章主要介绍了python中Harris角点检测的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
1、基本思想
选择在图像上任意方向的固定窗口进行滑动,如果灰度变化较大,则认为该窗口内部存在角点。
2、步骤
读图并将其转换为灰度图。
估计响应函数。
根据响应值选择角度。
画出原始图上的检测角点。
3、实例
from pylab import *from numpy import *from scipy.ndimage import filters def compute_harris_response(im,sigma=3): """ Compute the Harris corner detector response function for each pixel in a graylevel image. """ # derivatives imx = zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (0,1), imx) imy = zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (1,0), imy) # compute components of the Harris matrix Wxx = filters.gaussian_filter(imx*imx,sigma) Wxy = filters.gaussian_filter(imx*imy,sigma) Wyy = filters.gaussian_filter(imy*imy,sigma) # determinant and trace Wdet = Wxx*Wyy - Wxy**2 Wtr = Wxx + Wyy return Wdet / Wtr def get_harris_points(harrisim,min_dist=10,threshold=0.1): """ Return corners from a Harris response image min_dist is the minimum number of pixels separating corners and image boundary. """ # find top corner candidates above a threshold corner_threshold = harrisim.max() * threshold harrisim_t = (harrisim > corner_threshold) * 1 # get coordinates of candidates coords = array(harrisim_t.nonzero()).T # ...and their values candidate_values = [harrisim[c[0],c[1]] for c in coords] # sort candidates (reverse to get descending order) index = argsort(candidate_values)[::-1] # store allowed point locations in array allowed_locations = zeros(harrisim.shape) allowed_locations[min_dist:-min_dist,min_dist:-min_dist] = 1 # select the best points taking min_distance into account filtered_coords = [] for i in index: if allowed_locations[coords[i,0],coords[i,1]] == 1: filtered_coords.append(coords[i]) allowed_locations[(coords[i,0]-min_dist):(coords[i,0]+min_dist), (coords[i,1]-min_dist):(coords[i,1]+min_dist)] = 0 return filtered_coords def plot_harris_points(image,filtered_coords): """ Plots corners found in image. """ figure() gray() imshow(image) plot([p[1] for p in filtered_coords], [p[0] for p in filtered_coords],'*') axis('off') show()
from PIL import Imagefrom numpy import *# 这就是为啥上述要新建一个的原因,因为现在就可以importimport Harris_Detectorfrom pylab import *from scipy.ndimage import filters # filenameim = array(Image.open(r" ").convert('L'))harrisim=Harris_Detector.compute_harris_response(im)filtered_coords=Harris_Detector.get_harris_points(harrisim)Harris_Detector.plot_harris_points(im,filtered_coords)
感谢你能够认真阅读完这篇文章,希望小编分享的“Python中Harris角点检测的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网Python频道,更多相关知识等着你来学习!
--结束END--
本文标题: python中Harris角点检测的示例分析
本文链接: https://lsjlt.com/news/279632.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0