我正在尝试在OpenCV 2.4.9中使用新函数findEssentialMat()但是当我尝试编译我的程序时,它说没有定义findEssentialMat。我包括calib3d,我也链接了正确的库。
如何编译OpenCV以启用该功能?
这是我的计划:
#include“opencv2 / opencv.hpp”
使用命名空间std; 使用namespace cv;
Mat getEssential(const vector<KeyPoint>& keypoints1,const vector<KeyPoint>& keypoints2,vector<DMatch>& matches){
vector<Point2f> p1, p2;
for (vector<DMatch>::const_iterator it= matches.begin();it!= matches.end(); ++it) {
float x=keypoints1[it->queryIdx].pt.x;
float y=keypoints1[it->queryIdx].pt.y;
p1.push_back(Point2f(x,y));
x=keypoints2[it->trainIdx].pt.x;
y=keypoints2[it->trainIdx].pt.y;
p2.push_back(Point2f(x,y));
}
Mat output;
Mat essen = findEssentialMat(p1,p2,focal,pp,CV_RANSAC,0.99,1,output);
vector<DMatch> inliers;
for(int i=0;i<output.rows;i++){
int status=output.at<char>(i,0);
if(status==1){
inliers.push_back(matches[i]);
}
}
matches=inliers;
return essen;
}
int main(){
Ptr<FeatureDetector> fast = new FastFeatureDetector(10,true);
Ptr<FeatureDetector> detector = new PyramidAdaptedFeatureDetector(fast,3);
FREAK freak(true,true,22.0f,0);
BFMatcher matcher(NORM_HAMMING,true);
vector<DMatch> matches;
vector<KeyPoint> kp0,kp1;
Mat d0, d1;
Mat im0 = imread("/home/Chini/im0.png",0);
Mat im1 = imread("/home/Chini/im1.png",0);
detector->detect(im0,kp0,Mat());
detector->detect(im1,kp0,Mat());
freak.compute(im0,kp0,d0);
freak.compute(im1,kp1,d1);
matcher.match(d0,d1,matches);
Mat e = getEssential(kp0,kp1,matches);
}
当我尝试编译它时,我收到以下消息:
example.cpp: In function ‘cv::Mat getEssential(const std::vector<cv::KeyPoint>&, const std::vector<cv::KeyPoint>&, std::vector<cv::DMatch>&)’:
example.cpp:18:62: error: ‘findEssentialMat’ is not defined
提前致谢
答案 0 :(得分:4)
没有办法做到这一点
findEssentialMat()
是在3.x版本中实现的功能
按照“如何贡献OpenCV指南”这里: http://code.opencv.org/projects/opencv/wiki/How_to_contribute 2.4.x opencv版本已被冻结,其主要目的是为了与传统用户向后兼容,用他们的话说:
“2.4已被功能冻结;因此,不接受新功能。”
我强烈建议您安装3.x版本。
有一些很好的教程: http://embedonix.com/articles/image-processing/installing-opencv-3-1-0-on-ubuntu/#comment-125 http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/(最后一个对我有用)