cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python

回顾Harris角点检测:

Harris角点检测-OpenCV_独憩的博客-CSDN博客

Shi-Tomasi角点检测:

相比于Harris角点检测:

R=det(M)-k(trace(M))^2

Shi-Tomasi角点检测提出

R = min(\lambda _{1},\lambda _{2})

如果它大于一个阈值,就被认为是一个角。只有当λ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:指定感兴趣区,如不需在整幅图上寻找角点,则用此参数指定ROI

blockSize:计算协方差矩阵时的窗口大小

useHarrisDetector:指示是否使用Harris角点检测,如不指定,则计算shi-tomasi角点

harrisK:Harris角点检测需要的k值

一般来说,可以只输入image maxCorners, qualityLevel, minDistanc

Shi-Tomasi角点检测实例:

cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python_第1张图片

import cv2.cv2
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = 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)

cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python_第2张图片

 对比Harris角点检测:

import cv2.cv2
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = 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)

cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python_第3张图片

 很显然Shi-Tomasi角点检测的效果更好。

你可能感兴趣的:(opencv-python,学习,opencv,python,计算机视觉)