OpenCV哈里斯(Harris)角點(diǎn)檢測的實(shí)現(xiàn)
環(huán)境
pip install opencv-python==3.4.2.16 pip install opencv-contrib-python==3.4.2.16
理論
克里斯·哈里斯(Chris Harris)和邁克·史蒂芬斯(Mike Stephens)在1988年的論文《組合式拐角和邊緣檢測器》中做了一次嘗試找到這些拐角的嘗試,所以現(xiàn)在將其稱為哈里斯拐角檢測器。
函數(shù):cv2.cornerHarris(),cv2.cornerSubPix()
示例代碼
import cv2
import numpy as np
filename = 'molecule.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
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()
原圖

輸出圖

SubPixel精度的角落
import cv2
import numpy as np
filename = 'molecule.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# find Harris corners
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
dst = cv2.dilate(dst,None)
ret, dst = cv2.threshold(dst,0.01*dst.max(),255,0)
dst = np.uint8(dst)
# find centroids
ret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst)
# define the criteria to stop and refine the corners
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)
corners = cv2.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria)
# Now draw them
res = np.hstack((centroids,corners))
res = np.int0(res)
img[res[:,1],res[:,0]]=[0,0,255]
img[res[:,3],res[:,2]] = [0,255,0]
cv2.imwrite('subpixel5.png',img)
輸出圖

參考
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- OpenCV基于ORB算法實(shí)現(xiàn)角點(diǎn)檢測
- OpenCV角點(diǎn)檢測的實(shí)現(xiàn)示例
- Python中OpenCV圖像特征和harris角點(diǎn)檢測
- OpenCV半小時(shí)掌握基本操作之角點(diǎn)檢測
- OpenCV特征提取與檢測之Shi-Tomasi角點(diǎn)檢測器
- OpenCV特征提取與檢測之Harris角點(diǎn)檢測
- Android基于OpenCV實(shí)現(xiàn)Harris角點(diǎn)檢測
- python opencv角點(diǎn)檢測連線功能的實(shí)現(xiàn)代碼
- OpenCV實(shí)現(xiàn)圖像角點(diǎn)檢測
- opencv實(shí)現(xiàn)角點(diǎn)檢測
相關(guān)文章
Python Spyder 調(diào)出縮進(jìn)對齊線的操作
這篇文章主要介紹了Python Spyder 調(diào)出縮進(jìn)對齊線的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02
python實(shí)現(xiàn)對svn操作及信息獲取
這篇文章主要介紹了python實(shí)現(xiàn)對svn的操作及信息獲取示例過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-10-10
Python?中如何使用requests模塊發(fā)布表單數(shù)據(jù)
requests 庫是 Python 的主要方面之一,用于創(chuàng)建對已定義 URL 的 HTTP 請求,本篇文章介紹了 Python requests 模塊,并說明了我們?nèi)绾问褂迷撃K在 Python 中發(fā)布表單數(shù)據(jù),感興趣的朋友跟隨小編一起看看吧2023-06-06
python下載圖片實(shí)現(xiàn)方法(超簡單)
下面小編就為大家?guī)硪黄猵ython下載圖片實(shí)現(xiàn)方法(超簡單)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
Python Lambda函數(shù)使用總結(jié)詳解
這篇文章主要介紹了Python Lambda函數(shù)使用總結(jié)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12

