好久沒碰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不支持這些老顯卡了。
--------------------------------------分割線 --------------------------------------
Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm
Ubuntu 12.04 安裝 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm
CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm
Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm
Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm
基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm
[翻譯]Ubuntu 14.04, 13.10 下安裝 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2014-12/110045.htm
--------------------------------------分割線 --------------------------------------
OpenCV的詳細介紹:請點這裡
OpenCV的下載地址:請點這裡