OpenCV中重载函数的实例

Instance of overloaded function in OpenCV

本文关键字:实例 函数 重载 OpenCV      更新时间:2023-10-16

你好,我正试图实现一个快速特征检测器代码,在它的初始阶段,我得到以下错误

(1)没有重载函数"cv::FastFeatureDetector::detect"的实例匹配参数列表

(2)" keypointstoppoints "未定义

请帮帮我。

#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
int main()
{
  Mat img1 = imread("0000.jpg", 1);
  Mat img2 = imread("0001.jpg", 1);
 // Detect keypoints in the left and right images
FastFeatureDetector detector(50);
Vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
KeyPointsToPoints(left_keypoints,left_points);
vector<Point2f>right_points(left_points.size());
 return 0;
 }

问题在这一行:

Vector<KeyPoint> left_keypoints,right_keypoints;

c++是区分大小写的,它看到Vector是不同于vector的东西(它应该是什么)。为什么Vector工作超出了我的范围,我应该预料到一个错误。

cv::FastFeatureDetector::detect只知道如何与vector一起工作,而不是Vector,所以尝试修复这个错误,然后再试一次。

另外,KeyPointsToPoints在OpenCV库中不存在(除非你自己编程),请确保使用KeyPoint::convert(const vector<KeyPoint>&, vector<Point2f>&)进行转换。

给出的代码有一些小问题。首先,你缺少using namespace std,这是你使用矢量的方式所需要的。您还缺少矢量#include <vector>的包含。vector<KeyPoints>也应该有一个小写v.我也不确定keypointstoppoints是否是OpenCV的一部分。您可能必须自己实现这个函数。我不确定,我只是以前没见过。

#include <stdio.h>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img1 = imread("0000.jpg", 1);
Mat img2 = imread("0001.jpg", 1);
// Detect keypoints in the left and right images
FastFeatureDetector detector(50);
vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
for (int i = 0; i < left_keypoints.size(); ++i) 
{
    left_points.push_back(left_keypoints.pt);
}
vector<Point2f>right_points(left_points.size());
return 0;
}
我没有测试上面的代码。查看这里的OpenCV文档