gpt4 book ai didi

C++/CMake :Undefined reference to imwrite in OpenCV

转载 作者:太空宇宙 更新时间:2023-11-03 22:48:13 30 4
gpt4 key购买 nike

这是我的 CMakeLists.txt:

project(proj)
set(OpenCV_DIR "/usr/lib/opencv")
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)

include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test test.cpp>
target_link_libraries(test ${OpenCV_LIBS})

这是我的代码的一部分:

#include <opencv/cv.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.h>
#include <opencv/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argv, char **argc)
{
//other code
Mat img(height, width, CV_8UC3);
//other code

imwrite("/path", img);
namedWindow( "Display window", 1 );
imshow("Display window", img);

waitKey(0);
return 0;

}

我得到的错误信息是:

undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)`

imshow 工作正常,所以我不知道为什么 imwrite 给我一个错误。

编辑:

g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`

给出同样的错误。

最佳答案

在您的 find_package() 命令中,您只是从 OpenCV 包中选择一些特定的模块,以及您需要的模块 (imgcodecs提供 imwrite()) 不在列表中。

尝试将其更改为:

find_package(OpenCV)

关于C++/CMake :Undefined reference to imwrite in OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44165791/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com