好久没碰opencv了,现在已经3.0 beta了。
今天编译遇到了error: cannot declare variable ‘orb’ to be of abstract type ‘cv::ORB
原因是ORB这个类不能再这么调用了。
在opencv 根目录找到opencvroot/samples/gpu/performance/tests.cpp
修改成如下代码。
TEST(ORB)
{
? ? Mat src = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
? ? if (src.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
? ? //ORB orb(4000);
? ? Ptr orb = ORB::create(4000,1.2f,8,31,0,2,ORB::HARRIS_SCORE,31,20);
? ? vector keypoints;
? ? Mat descriptors;
? ?
? ? orb->detectAndCompute(src, Mat(), keypoints, descriptors);
? ? //orb(src, Mat(), keypoints, descriptors);
? ? CPU_ON;
? ? //orb(src, Mat(), keypoints, descriptors);
? ? orb->detectAndCompute(src, Mat(), keypoints, descriptors);
? ? CPU_OFF;
? ? cuda::ORB_CUDA d_orb;
? ? cuda::GpuMat d_src(src);
? ? cuda::GpuMat d_keypoints;
? ? cuda::GpuMat d_descriptors;
? ? d_orb(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
? ? CUDA_ON;
? ? d_orb(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
? ? CUDA_OFF;
}
这里说明原因,我查看了opencv3.0的feature2d.hpp代码发现
class CV_EXPORTS_W ORB : public Feature2D?
{?
public:?
? ? enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };?
?
? ? CV_WRAP static Ptr create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31,?
? ? ? ? int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20);
?
? ? CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;?
? ? CV_WRAP virtual int getMaxFeatures() const = 0;?
?
? ? CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;?
? ? CV_WRAP virtual double getScaleFactor() const = 0;?
?
? ? CV_WRAP virtual void setNLevels(int nlevels) = 0;?
? ? CV_WRAP virtual int getNLevels() const = 0;?
?
? ? CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;?
? ? CV_WRAP virtual int getEdgeThreshold() const = 0;?
?
? ? CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;?
? ? CV_WRAP virtual int getFirstLevel() const = 0;?
?
? ? CV_WRAP virtual void setWTA_K(int wta_k) = 0;?
? ? CV_WRAP virtual int getWTA_K() const = 0;?
?
? ? CV_WRAP virtual void setScoreType(int scoreType) = 0;?
? ? CV_WRAP virtual int getScoreType() const = 0;?
?
? ? CV_WRAP virtual void setPatchSize(int patchSize) = 0;?
? ? CV_WRAP virtual int getPatchSize() const = 0;?
?
? ? CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;?
? ? CV_WRAP virtual int getFastThreshold() const = 0;?
};?
没有构造函数,只有一个静态的create。
此外,检测函数也不能用原来的操作符重载的检测函数了。
class ORB_Impl : public ORB?
{?
public:?
? ? explicit ORB_Impl(int _nfeatures, float _scaleFactor, int _nlevels, int _edgeThreshold,?
? ? ? ? ? ? int _firstLevel, int _WTA_K, int _scoreType, int _patchSize, int _fastThreshold) :?
? ? ? ? nfeatures(_nfeatures), scaleFactor(_scaleFactor), nlevels(_nlevels),?
? ? ? ? edgeThreshold(_edgeThreshold), firstLevel(_firstLevel), wta_k(_WTA_K),?
? ? ? ? scoreType(_scoreType), patchSize(_patchSize), fastThreshold(_fastThreshold)?
? ? {}?
?
? ? void setMaxFeatures(int maxFeatures) { nfeatures = maxFeatures; }?
? ? int getMaxFeatures() const { return nfeatures; }?
?
? ? void setScaleFactor(double scaleFactor_) { scaleFactor = scaleFactor_; }?
? ? double getScaleFactor() const { return scaleFactor; }?
?
? ? void setNLevels(int nlevels_) { nlevels = nlevels_; }?
? ? int getNLevels() const { return nlevels; }?
?
? ? void setEdgeThreshold(int edgeThreshold_) { edgeThreshold = edgeThreshold_; }?
? ? int getEdgeThreshold() const { return edgeThreshold; }?
?
? ? void setFirs