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半小時掌握基本操作之角點(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)文章
解決pycharm不能自動補(bǔ)全第三方庫的函數(shù)和屬性問題
這篇文章主要介紹了解決pycharm不能自動補(bǔ)全第三方庫的函數(shù)和屬性問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Python?pycharm提交代碼遇到?jīng)_突解決方法
這篇文章主要介紹了Python?pycharm提交代碼遇到?jīng)_突解決方法,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08
python實(shí)現(xiàn)nao機(jī)器人手臂動作控制
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)nao機(jī)器人手臂動作控制,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-04-04
YOLOv5中SPP/SPPF結(jié)構(gòu)源碼詳析(內(nèi)含注釋分析)
其實(shí)關(guān)于YOLOv5的網(wǎng)絡(luò)結(jié)構(gòu)其實(shí)網(wǎng)上相關(guān)的講解已經(jīng)有很多了,但是覺著還是有必要再給大家介紹下,下面這篇文章主要給大家介紹了關(guān)于YOLOv5中SPP/SPPF結(jié)構(gòu)源碼的相關(guān)資料,需要的朋友可以參考下2022-05-05

