好久没碰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 = ORB::create(4000,1.2f,8,31,0,2,ORB::HARRIS_SCORE,31,20);
vector<KeyPoint> 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<ORB> 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 setFirstLevel(int firstLevel_) { firstLevel = firstLevel_; }
int getFirstLevel() const { return firstLevel; }
void setWTA_K(int wta_k_) { wta_k = wta_k_; }
int getWTA_K() const { return wta_k; }
void setScoreType(int scoreType_) { scoreType = scoreType_; }
int getScoreType() const { return scoreType; }
void setPatchSize(int patchSize_) { patchSize = patchSize_; }
int getPatchSize() const { return patchSize; }
void setFastThreshold(int fastThreshold_) { fastThreshold = fastThreshold_; }
int getFastThreshold() const { return fastThreshold; }
// returns the descriptor size in bytes
int descriptorSize() const;
// returns the descriptor type
int descriptorType() const;
// returns the default norm type
int defaultNorm() const;
// Compute the ORB_Impl features and descriptors on an image
<strong>void detectAndCompute( InputArray image, InputArray mask, std::vector<KeyPoint>& keypoints,
OutputArray descriptors, bool useProvidedKeypoints=false );</strong>
protected:
int nfeatures;
double scaleFactor;
int nlevels;
int edgeThreshold;
int firstLevel;
int wta_k;
int scoreType;
int patchSize;
int fastThreshold;
};
希望有人遇到这样的问题的时候,能够得到解答。
此外还有就是使用最新的cuda6.5的时候一定要在gui的cmake 中
将CUDA_ARCH_BIN 设置为2.0 2.1(2.0) 3.0 3.5
不要带1.1 .1.2 1.3等等之类的,因为cuda6.5不支持这些老显卡了。
--------------------------------------分割线 --------------------------------------