编译时SIFT代码(C ++)中的未定义引用

用户名

我正在尝试检测关键点并提取一组图像的描述符,并将它们存储在文本文件中以进行匹配(这将由另一段代码处理)。这就是我目前拥有的所有代码。

以下是我试图通过在Ubuntu 12.04终端上使用g ++ sift1.cpp进行编译的代码。我已经安装了OpenCV 2.4.9。

#include <iostream>
#include <stdio.h>
#include <dirent.h>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    if(argc != 2)
    {
        cout << "Usage: ./output <database path>" << endl;
        return -1;
    }
    Mat img;
    vector<KeyPoint> keypoints;
    //  SiftFeatureDetector detector;
    //  vector<KeyPoint> keypoints;
    //      detector.detect(img, keypoints);
    Mat descriptor;
    SIFT sift;
    Mat frame_gray;
    //  vector<Rect> faces;
    ofstream outfile_kp, outfile_des;
    outfile_kp.open("keypoints_file.txt");
    outfile_des.open("descriptors_file.txt");
    DIR *pdir = NULL;
    pdir = opendir(argv[1]);
    struct dirent *pent = NULL;
    while(pent == readdir(pdir))
    {
        if((strcmp(pent -> d_name, ".") == 0) || (strcmp(pent -> d_name, "..") == 0))
        {
            continue;
        }
        img = imread(pent -> d_name, CV_LOAD_IMAGE_GRAYSCALE);
        cvtColor( img, frame_gray, CV_BGR2GRAY );
        equalizeHist( frame_gray, frame_gray );
        sift.operator()(frame_gray,frame_gray,keypoints,descriptor,false);
        //      std::ostream_iterator<KeyPoint> output_iterator_kp(outfile_kp, "\n");
        //      std::copy(keypoints.begin(), keypoints.end(), output_iterator_kp);
        //      outfile_des << descriptor << endl;
        //      std::ostream_iterator<KeyPoint> output_iterator_des(output_des, "\n");
        //      std::copy(keypoints.begin(), keypoints.end(), output_iterator_des);
        //      outfile_kp << keypoints << endl;
        //      outfile_des << descriptor << endl;
    }
    outfile_kp.close();
    outfile_des.close();
    /*
       Mat img_keypoints;      drawkeypoints(img,keypoints,img_keypoints,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
       imshow("keypoints",img_keypoints);
     */
    waitKey(0);
    return 0;
}

以下是我得到的错误:

/tmp/ccqW6zsl.o: In function `main':
sift1.cpp:(.text+0xc1): undefined reference to `cv::SIFT::SIFT(int, int, double, double, double)'
sift1.cpp:(.text+0x20e): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
sift1.cpp:(.text+0x26b): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
sift1.cpp:(.text+0x283): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
sift1.cpp:(.text+0x2ab): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
sift1.cpp:(.text+0x2c3): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
sift1.cpp:(.text+0x2db): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
sift1.cpp:(.text+0x2f3): undefined reference to `cv::equalizeHist(cv::_InputArray const&, cv::_OutputArray const&)'
sift1.cpp:(.text+0x30b): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
sift1.cpp:(.text+0x323): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
sift1.cpp:(.text+0x33b): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
sift1.cpp:(.text+0x379): undefined reference to `cv::SIFT::operator()(cv::_InputArray const&, cv::_InputArray const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::_OutputArray const&, bool) const'
sift1.cpp:(.text+0x3c3): undefined reference to `cv::waitKey(int)'
/tmp/ccqW6zsl.o: In function `cv::Mat::~Mat()':
sift1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference to `cv::fastFree(void*)'
/tmp/ccqW6zsl.o: In function `cv::Mat::operator=(cv::Mat const&)':
sift1.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0xf2): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccqW6zsl.o: In function `cv::Mat::release()':
sift1.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3b): undefined reference to `cv::Mat::deallocate()'
/tmp/ccqW6zsl.o: In function `cv::Feature2D::~Feature2D()':
sift1.cpp:(.text._ZN2cv9Feature2DD2Ev[cv::Feature2D::~Feature2D()]+0x46): undefined reference to `cv::DescriptorExtractor::~DescriptorExtractor()'
sift1.cpp:(.text._ZN2cv9Feature2DD2Ev[cv::Feature2D::~Feature2D()]+0x5b): undefined reference to `cv::FeatureDetector::~FeatureDetector()'
sift1.cpp:(.text._ZN2cv9Feature2DD2Ev[cv::Feature2D::~Feature2D()]+0x72): undefined reference to `cv::Algorithm::~Algorithm()'
sift1.cpp:(.text._ZN2cv9Feature2DD2Ev[cv::Feature2D::~Feature2D()]+0xa2): undefined reference to `cv::FeatureDetector::~FeatureDetector()'
sift1.cpp:(.text._ZN2cv9Feature2DD2Ev[cv::Feature2D::~Feature2D()]+0xbd): undefined reference to `cv::Algorithm::~Algorithm()'
/tmp/ccqW6zsl.o: In function `cv::SIFT::~SIFT()':
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x1e): undefined reference to `vtable for cv::SIFT'
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x30): undefined reference to `vtable for cv::SIFT'
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x37): undefined reference to `vtable for cv::SIFT'
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x42): undefined reference to `VTT for cv::SIFT'
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x6b): undefined reference to `cv::Algorithm::~Algorithm()'
sift1.cpp:(.text._ZN2cv4SIFTD1Ev[cv::SIFT::~SIFT()]+0x9d): undefined reference to `cv::Algorithm::~Algorithm()'
collect2: ld returned 1 exit status

我无法解决这些问题。任何见识将不胜感激。提前致谢。

雷瑞恩

您遇到的是编译代码时的链接器错误。这是因为在编译代码时,编译器找不到OpenCV库。因此,在编译代码时,需要与OpenCV库链接。

简而言之,执行以下操作:

$ g++ -Wall -g -o sift sift.cpp `pkg-config --cflags --libs opencv` 

上述用于g++启用所有警告,启用调试模式的选项将使输出可执行文件名为sift

要在之后运行代码,请执行以下操作:

$ ./sift

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

编译时SIFT代码(C ++)中的未定义引用

来自分类Dev

C Opengl中的未定义引用

来自分类Dev

对C ++中函数的未定义引用

来自分类Dev

对C ++中函数的未定义引用

来自分类Dev

在C ++代码中对C函数的未定义引用

来自分类Dev

编译代码时未定义对“main”的引用

来自分类Dev

在C ++中链接静态库时对...的未定义引用

来自分类Dev

无法编译C ++代码-“未定义的引用-”

来自分类Dev

C ++未定义的引用

来自分类Dev

未定义对函数“ check”的引用(MinGW中的GCC编译)

来自分类Dev

C编译-“未定义引用”?

来自分类Dev

为什么在此代码中得到未定义的引用?

来自分类Dev

使用libpng从IPOL构建代码中的未定义引用

来自分类Dev

在C编程中,编译时出现“未定义引用”错误是什么?

来自分类Dev

在子文件夹中编译.h和.cpp时的C ++未定义引用

来自分类Dev

错误:编译C ++时出现“未定义引用”

来自分类Dev

编译C ++时对main的未定义引用

来自分类Dev

在最小的C程序中未定义对“ main”的引用

来自分类Dev

静态库中对C ++ 11原子的未定义引用

来自分类Dev

C中对mat.h的未定义引用

来自分类Dev

QT C ++中对全局变量的未定义引用

来自分类Dev

类c ++中的静态成员未定义引用

来自分类Dev

C ++中对类成员的“未定义”引用

来自分类Dev

在C程序中未定义对函数的引用

来自分类Dev

在函数中未定义的引用 c++

来自分类Dev

GetPhysicallyInstalledMemory 函数 - C 中未定义的引用

来自分类Dev

编译错误:未定义引用

来自分类Dev

编译错误:未定义引用

来自分类Dev

编译C代码时未定义的参考