opencv-108-特征提取之关键点检测(GFTTDetector)

知识点

该方法是基于shi-tomas角点检测变化而来的一种特征提取方法,OpenCV创建该检测器的API与goodfeaturetotrack的API参数极其类似:

1
2
3
4
5
6
7
8
9
10
11
Ptr<GFTTDetector> cv::GFTTDetector::create(
int maxCorners = 1000,
double qualityLevel = 0.01,
double minDistance = 1,
int blockSize = 3,
bool useHarrisDetector = false,
double k = 0.04
)
唯一不同的,该方法返回一个指针。

该方法无法提取描述子,只支持提取关键点!

代码(c++,python)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
Mat src = imread("D:/images/test1.png");
auto keypoint_detector = GFTTDetector::create(1000, 0.01, 1.0, 3, false, 0.04);
vector<KeyPoint> kpts;
keypoint_detector->detect(src, kpts);
Mat result = src.clone();
drawKeypoints(src, kpts, result, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
imshow("GFTT-Keypoint-Detect", result);
imwrite("D:/result.png", result);
waitKey(0);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""
特征提取之关键点检测(GFTTDetector)
"""

import cv2 as cv

image = cv.imread("images/test4.jpg")
cv.imshow("input", image)

# 创建GFTT特征检测器
gftt = cv.GFTTDetector_create(100, 0.01, 1, 3, False, 0.04)
kp1 = gftt.detect(image, None)
for marker in kp1:
result = cv.drawMarker(image, tuple(int(i) for i in marker.pt), color=(0, 255, 0))

cv.imshow("GFTT-Keypoint-Detect", result)
cv.waitKey(0)
cv.destroyAllWindows()

结果

代码地址

github