更新日志

04-09

Harris Corner Detect


一 前言

在计算机视觉的领域中,有着两类十分基本的任务:

  • 识别(Recognition)
  • 测距(Distance)

这篇博客以全景拼接的角度,从兴趣点检测出发,逐步认知识别任务。

全景拼接有5个基本步骤:

  1. 特征点检测(Keypoints Detection)
  2. 构建特征描述符(Construct Feature Descriptor)
  3. 点对匹配(Corresponding Pair Match)
  4. 求出变换矩阵(Compute Transform Matrix)
  5. 变换拼接(Stitch Panorama)

以下说明特征点检测的两大方法。

二 Harris 角点检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def harris(filename: str="Images/lenna_img.jpg"):
img = cv2.imread(filename)
img_copy = cv2.imread(filename) # Copy a couterpart
# Covert to gray image
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_img = np.float32(gray_img)

# harris Detection
Harris_detector = cv2.cornerHarris(gray_img, 2, 3, 0.04)

# harris non-extrmum suppression
dst = cv2.dilate(Harris_detector, None)

# Set a threshold for display
thres = 0.01 * dst.max()
img[dst > thres] = [0, 255, 0]
imgs = np.hstack([img_copy, img])

img_new = imgs[:, :, ::-1]
plt.xticks([]), plt.yticks([]) # 隐藏x和y轴
plt.imshow(img_new)
plt.axis("off")

cv2.imshow('show', imgs)
cv2.waitKey()

image-20230409225306775