图像识别主要有特征点识别、特征点提取、特征点匹配三个过程。这里主要是利用特征点识别中的FAST算法,对图片上的特征点进行识别,然后添加到图片上进行展示,FAST算法计算比较迅速,但是缺点也很明显,就是点太多了,很多都是没有用的点。
代码如下:
# 导入cv模块
import cv2
frame = cv2.imread("timg.jpg", 1)
title = "image"
point_size = 1
point_color = (0, 0, 255) # BGR
thickness = 4 # 可以为 0 、4、8
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
detector = cv2.FastFeatureDetector_create()
kps = detector.detect(gray)
for point in kps:
position = (int(point.pt[0]), int(point.pt[1]))
cv2.circle(frame, position, point_size, point_color, thickness)
# 创建窗口并显示图像
cv2.namedWindow(title, cv2.WINDOW_NORMAL)
cv2.imshow(title, frame)
cv2.waitKey(0)
# 释放窗口
cv2.destroyAllWindows()
结果图如下图所示: