Harris角點(diǎn))
1.python提取Harris角點(diǎn)其實(shí)有在網(wǎng)上參考部分代碼但是有些博客的博主可能連代碼都沒跑過(guò)直接網(wǎng)上找資源就粘貼在自己的博客下了然而有些代碼是會(huì)報(bào)錯(cuò)的第一行就報(bào)錯(cuò)SyntaxError: invalid syntax應(yīng)該是pre name code class python這一行代碼出現(xiàn)的問(wèn)題。但是我查閱了好多博客解釋居然都一模一樣直接這么復(fù)制黏貼真的好嘛我最后也沒解決這個(gè)問(wèn)題但是我發(fā)現(xiàn)這一行并不需要注釋掉功能仍可以正常使用。如果有小伙伴能解釋一下那我是完全歡迎的這里一共有兩個(gè).py文件第一個(gè)命名為harris.py相當(dāng)于自己定義了一個(gè)module第二個(gè)看你喜好O(∩_∩)O# pre name code class python #coding:utf-8fromscipy.ndimageimportfiltersfromnumpyimport*frompylabimport*defcompute_harris_response(im,sigma3):imxzeros(im.shape)#計(jì)算導(dǎo)數(shù)filters.gaussian_filter(im,(sigma,sigma),(0,1),imx)imyzeros(im.shape)filters.gaussian_filter(im,(sigma,sigma),(1,0),imy)Wxxfilters.gaussian_filter(imx*imx,sigma)#計(jì)算harris矩陣分量Wxyfilters.gaussian_filter(imx*imy,sigma)Wyyfilters.gaussian_filter(imy*imy,sigma)#計(jì)算矩陣的特征值和跡WtrWxxWyyreturnWdet/Wtrdefget_harris_points(harrisim,min_dist10,threshold0.1):conner_thresholdharrisim.max()*threshold harrisim_t(harrisimconner_threshold)*1coordsarray(harrisim_t.nonzero()).T candidate_values[harrisim[c[0],c[1]]forcincoords]indexargsort(candidate_values)allowed_locationszeros(harrisim.shape)allowed_locations[min_dist:-min_dist,min_dist:-min_dist]1filtered_coords[]foriinindex:ifallowed_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#此處保證min_dist*min_dist只有一個(gè)harris特征點(diǎn)returnfiltered_coordsdefplot_harris_points(image,filtered_coords):figure()gray()imshow(image)plot([p[1]forpinfiltered_coords],[p[0]forpinfiltered_coords],)axis(off)show()#coding:utf-8fromscipy.ndimageimportfiltersfromnumpyimport*fromPILimportImageimportharrisfrompylabimport*forfilenameinos.listdir(r/path to your image):print(filename)imarray(Image.open(/path to your imagefilename).convert(L))harrisimharris.compute_harris_response(im)filtered_coordsharris.get_harris_points(harrisim,6)harris.plot_harris_points(im,filtered_coords)