【发布时间】:2015-01-25 00:10:10
【问题描述】:
我正在尝试创建一个可以在图像中找到关键点的类。但是,我遇到了一个荒谬的错误,我不知道如何解决。
现在的问题是
this->detector
为零,因此由于某种原因未正确初始化。我在谷歌上搜索过,但我没有找到任何东西。
我的头文件如下所示
/*
* FindKeyPoints.h
*
* Created on: Jan 21, 2015
* Author: erikbylow
*/
#ifndef FINDKEYPOINTS_H_
#define FINDKEYPOINTS_H_
#include <vector>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
using namespace std;
class FindKeyPoints {
private:
// Create vector of KeyPoints to store the detected keypoint in
vector<cv::KeyPoint> keyPointsOld;
vector<cv::KeyPoint> keyPointsNew;
// Threshold for similarity
const int THRESHOLD = 10;
// Instance(?) DescriptionExtractor and descriptor
cv::Ptr<cv::DescriptorExtractor> descriptionExtractor;
cv::Ptr<cv::FeatureDetector> detector;
public:
FindKeyPoints(const string &METHOD);
virtual ~FindKeyPoints();
void detectKeypoints(cv::Mat& imgNew, cv::Mat& imgOld);
};
#endif /* FINDKEYPOINTS_H_ */
构造函数看起来像
FindKeyPoints::FindKeyPoints(const string &METHOD) {
cout<<METHOD<<endl;
cv::initModule_features2d();
this->detector = cv::FeatureDetector::create("SURF");
//this->descriptionExtractor = cv::DescriptorExtractor::create(METHOD);
}
我将使用的函数如下所示:
// Input: The new image and the old image. Find Keypoints and extract the descriptors.
void FindKeyPoints::detectKeypoints(cv::Mat& imgNew,
cv::Mat& imgOld) {
if (this->detector == 0){
cout<<"Hej"<<endl;
}
// this->detector->detect(imgNew, keyPointsNew);
// this->detector->detect(imgOld, keyPointsOld);
}
我使用 cmake 并且(部分)我的 CMakeLists.txt 看起来像:
TARGET_LINK_LIBRARIES(${PROJECT_NAME} groundtruth ${OpenCV_LIBS} ${QT_LIBRARIES}
${QGLViewer_LIBRARIES} ${OPENGL_gl_LIBRARY} GL
glut)
可以吗
${OpenCV_LIBS}
不包括 libopencv_nonfree.so 吗?
问候
【问题讨论】:
-
您的代码没有问题。您是否将所有必要的 .lib 包含到您的项目中?
-
我把我的 CMakeLists.txt 放在了问题中
-
您的“可笑”错误是什么?你能把它和完整的堆栈跟踪放在一起吗
-
#0 0x00007ffff792d02e in cv::FeatureDetector::detect(cv::Mat const&, std::vector<:keypoint std::allocator> >&, cv ::Mat const&) const () from /usr/local/lib/libopencv_features2d.so.2.4 #1 0x000000000041be7b in FindKeyPoints::detectKeypoints(cv::Mat&, cv::Mat&) () #2 0x000000000041b79a in main ()
标签: c++ opencv feature-detection