HM *_*man 6 feature-extraction keypoint corner-detection
cv::cornerHarris()来检测角落(我可以轻松做到)。std::vector<KeyPoint>(我不知道该怎么做)。稍后我将使用它来计算描述符并匹配它们。我可以很容易地使用 SURF 来完成它们,但我想使用 Harris 角点检测器来完成。
/// Detecting corners
cv::cornerHarris(leftRoi, dst, blockSize, apertureSize, k, BORDER_DEFAULT);
/// Normalizing
normalize(dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
convertScaleAbs(dst_norm, dst_norm_scaled);
/// Drawing a circle around corners
for (int j = 0; j < dst_norm.rows; j++)
{
for (int i = 0; i < dst_norm.cols; i++)
{
if ((int)dst_norm.at<float>(j, i) > 165)
{
circle(dst_norm_scaled, Point(i, j), 5, Scalar(0), 2, 8, 0);
}
}
}
/// Showing the result
namedWindow("corners_window", CV_WINDOW_AUTOSIZE);
imshow("corners_window", dst_norm_scaled);
Run Code Online (Sandbox Code Playgroud)-这部分有问题(我如何从上面的哈里斯探测器中提取关键点)
std::vector<KeyPoint> keypoints;
Run Code Online (Sandbox Code Playgroud)
这是我用 Python 编写的:
# convert coordinates to Keypoint type
eye_corner_keypoints = [cv2.KeyPoint(crd[0], crd[1], 13) for crd in eye_corner_coordinates]
# compute SIFT descriptors from corner keypoints
sift = cv2.xfeatures2d.SIFT_create()
eye_corner_descriptors = [sift.compute(gray,[kp])[1] for kp in eye_corner_keypoints]
Run Code Online (Sandbox Code Playgroud)
查看 OpenCV参考文档中KeyPoint 类的构造函数签名:
KeyPoint (float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1)
Run Code Online (Sandbox Code Playgroud)
看起来您可以迭代坐标点并在每次迭代时(大致)实例化您的 KeyPoint 对象,如下所示:
for (int i = 0; i < num_points; i++) {
KeyPoint kp(points_x[i], points_y[i], points_size[i]);
/* ... */
Run Code Online (Sandbox Code Playgroud)
警告:代码未经测试,我不是 C++ 程序员。
| 归档时间: |
|
| 查看次数: |
4604 次 |
| 最近记录: |