对cv :: imread

时间:2019-03-21 17:18:39

标签: c++ opencv

我正在写一个新问题,因为我发现的所有解决方案似乎都不起作用...

我使用以下选项编译了OpenCV 4.0.1:

cmake -DCMAKE_BUILD_TYPE=RELEASE \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \
-DOPENCV_TEST_DATA_PATH=../../opencv_extra-4.0.1/testdata \
-DWITH_OPENGL=ON \
-DWITH_OPENCL=ON \
-DBUILD_TIFF=ON \
-DWITH_IPP=ON \
-DWITH_TBB=ON \
-DWITH_EIGEN=ON \
-DWITH_V4L=ON \
-DBUILD_opencv_java=OFF \
-DWITH_CUDA=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
..

现在我正在尝试编译一个简单的脚本来测试一切是否正常:

#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
    std::string path = "picture.jpg";
    cv::Mat img = cv::imread(path.c_str(), -1);
    return 0;
}

使用命令

g++ -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lm -L /usr/local/lib/ -I /usr/local/include/opencv4/ test.cpp -o test

我收到此错误:

/tmp/ccrKkLP8.o: In function `main':
test.cpp:(.text+0xa7): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/tmp/ccrKkLP8.o: In function `cv::Mat::~Mat()':
test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccrKkLP8.o: In function `cv::Mat::release()':
test.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

有什么想法吗?

---解决方案---

我必须在这里写下它,因为问题已关闭...问题是按g++的参数顺序排列的。在将源文件放在g ++之后,它起作用了。正确的命令是:

g++ test.cpp -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lm -L /usr/local/lib/ -I /usr/local/include/opencv4/ -o test

0 个答案:

没有答案