Opencv Python 简明教程
OpenCV Python - Feature Detection
在图像处理中,特征是图像关键区域的数学描述。它们是图像视觉内容的矢量表示。
In the context of image processing, features are mathematical representations of key areas in an image. They are the vector representations of the visual content from an image.
特征使得能够对它们进行数学运算。各种计算机视觉应用包括目标检测、运动估计、分割、图像对齐等。
Features make it possible to perform mathematical operations on them. Various computer vision applications include object detection, motion estimation, segmentation, image alignment etc.
任何图像中的突出特征包括边缘、角或图像的部分。OpenCV 支持 Haris corner detection 和 Shi-Tomasi corner detection 算法。OpenCV 库还提供用于实现 SIFT (尺度不变特征变换)、 SURF (加速稳健特征)和角检测快速算法的功能。
Prominent features in any image include edges, corners or parts of an image. OpenCV supports Haris corner detection and Shi-Tomasi corner detection algorithms. OpenCV library also provides functionality to implement SIFT (Scale-Invariant Feature Transform), SURF(Speeded-Up Robust Features) and FAST algorithm for corner detection.
Harris 和 Shi-Tomasi 算法是旋转不变的。即使图像旋转,我们也可以找到相同的角。但是当图像被放大时,图像中的某个角可能不再是角。下图描述了这一点。
Harris and Shi-Tomasi algorithms are rotation-invariant. Even if the image is rotated, we can find the same corners. But when an image is scaled up, a corner may not be a corner if the image. The figure given below depicts the same.
D.Lowe 的新算法 Scale Invariant Feature Transform (SIFT)提取关键点并计算其描述符。
D.Lowe’s new algorithm, Scale Invariant Feature Transform (SIFT) extracts the key points and computes its descriptors.
这是通过以下步骤实现的 −
This is achieved by following steps −
-
Scale-space Extrema Detection.
-
Keypoint Localization.
-
Orientation Assignment.
-
Keypoint Descriptor.
-
Keypoint Matching.
至于 OpenCV 中 SIFT 的实现,它从加载图像并将其转换为灰度开始。 cv.SHIFT_create() 函数创建 SIFT 对象。
As far as implementation of SIFT in OpenCV is concerned, it starts from loading an image and converting it into grayscale. The cv.SHIFT_create() function creates a SIFT object.
Example
调用其 detect() 方法可获得绘制在原始图像顶部的关键点。以下代码实现了此过程
Calling its detect() method obtains key points which are drawn on top of the original image. Following code implements this procedure
import numpy as np
import cv2 as cv
img = cv.imread('home.jpg')
gray= cv.cvtColor(img,cv.COLOR_BGR2GRAY)
sift = cv.SIFT_create()
kp = sift.detect(gray,None)
img=cv.drawKeypoints(gray,kp,img)
cv.imwrite('keypoints.jpg',img)