本文主要是介绍cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
回顾Harris角点检测:
Harris角点检测-OpenCV_独憩的博客-CSDN博客
Shi-Tomasi角点检测:
相比于Harris角点检测:
Shi-Tomasi角点检测提出
如果它大于一个阈值,就被认为是一个角。只有当λ1和λ2高于一个最小值λmin时,它才被认为是一个角。
corners = cv.goodFeaturesToTrack( image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]] )image:8位或32位浮点型输入图像,单通道maxCorners:角点数目最大值,如果实际检测的角点超过此值,则只返回前maxCorners个强角点qualityLevel:角点的品质因子,0-1中的数字minDistance:对于初选出的角点而言,如果在其周围minDistance范围内存在其他更强角点,则将此角点删除_mask:指定感兴趣区,如不需在整幅图上寻找角点,则用此参数指定ROIblockSize:计算协方差矩阵时的窗口大小useHarrisDetector:指示是否使用Harris角点检测,如不指定,则计算shi-tomasi角点harrisK:Harris角点检测需要的k值一般来说,可以只输入image maxCorners, qualityLevel, minDistanc
Shi-Tomasi角点检测实例:
import cv2.cv2
import numpy as np
import cv2 as cv
from matplotlib import pyplot as pltimg = cv.imread(r'XXXXX.jpg')
img = cv2.resize(img, (0, 0), fx=0.1, fy=0.1, interpolation=cv2.INTER_NEAREST)
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
corners = cv.goodFeaturesToTrack(gray,45,0.01,10)
corners = np.int0(corners)
#img = cv.cvtColor(img,cv.COLOR_BGR2RGB)
for i in corners:x,y = i.ravel()cv.circle(img,(x,y),5,(0,0,255),-1)
cv.imwrite(r'XXXXXX.jpg',img)
对比Harris角点检测:
import cv2.cv2
import numpy as np
import cv2 as cv
from matplotlib import pyplot as pltimg = cv.imread(r'XXXX\beatiful.jpg')
img = cv2.resize(img, (0, 0), fx=0.1, fy=0.1, interpolation=cv2.INTER_NEAREST)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv.cornerHarris(gray, 2, 3, 0.04)dst = cv.dilate(dst, None)img[dst > 0.01 * dst.max()] = [0, 0, 255]
cv.imshow('dst', img)
cv.waitKey(0)
cv.imwrite(r'C:\Users\12860\Desktop\beatiful1.jpg',img)
很显然Shi-Tomasi角点检测的效果更好。
这篇关于cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!