0

我是 ubuntu 中的 opencv 新手。我已经按照这里的教程在 linux 中设置 opencv。但是,我未能使示例程序运行。在我输入以下内容后,

$ g++ DisplayImage.cpp

出现这些错误,

/tmp/cc3GTOtQ.o: In function `main':
DisplayImage.cpp:(.text+0x53): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0xe5): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0x113): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x147): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
DisplayImage.cpp:(.text+0x169): undefined reference to `cv::waitKey(int)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::~Mat()':
DisplayImage.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::operator=(cv::Mat const&)':
DisplayImage.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::release()':
DisplayImage.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
4

2 回答 2

2

这是带有 OpenCV 库的完整命令行构建 C++ 程序。

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binaryName  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy

如果您将 OpenCV 安装在不同的位置,则应将“include”和 lib“目录”的路径更改为适当的位置。

编辑:-

不要每次都运行这个命令,只需build.sh在项目目录中创建一个文件,而是通过运行将其权限更改为可执行,chmod 777 build.sh而构建项目只需运行这个文件。

于 2013-11-11T06:28:50.743 回答
0

您需要与 opencv 库链接:您可能需要至少添加-lcv和可能添加-lcxcore-lhighgui您的命令行。看到这个类似的问题

于 2013-11-11T06:04:50.587 回答