gpt4 book ai didi

c++ - 有没有办法修复编译器找不到特定的 openCV 变量/函数?

转载 作者:太空狗 更新时间:2023-10-29 21:10:03 27 4
gpt4 key购买 nike

经过长时间的努力,我刚刚安装了 openCV 3.2.0。我尝试编写一个程序来加载图像,将其转换为灰度,写入然后显示两者。问题是每当我尝试运行时

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

我得到以下内容

main.cpp: In function ‘int main()’:
main.cpp:14:27: error: ‘COLOR_BGR2GRAY’ was not declared in this scope
cvtColor(image, gImage, COLOR_BGR2GRAY);
^~~~~~~~~~~~~~
main.cpp:14:27: note: suggested alternative: ‘CV_BGR2GRAY’
cvtColor(image, gImage, COLOR_BGR2GRAY);
^~~~~~~~~~~~~~
CV_BGR2GRAY
main.cpp:14:3: error: ‘cvtColor’ was not declared in this scope
cvtColor(image, gImage, COLOR_BGR2GRAY);
^~~~~~~~
main.cpp:14:3: note: suggested alternative: ‘cvCvtColor’
cvtColor(image, gImage, COLOR_BGR2GRAY);
^~~~~~~~
cvCvtColor

我正在阅读 openCV 教程,我正在阅读我的版本 3.2.0,它使用的是我尝试使用的名称。

这是我的代码:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;

int main()
{
Mat image = imread("test.jpeg", 1);
Mat gImage;
cvtColor(image, gImage, COLOR_BGR2GRAY);

imwrite("test_gray.jpeg", gImage);

namedWindow("Display image", WINDOW_AUTOSIZE);
imshow("Display image", image);

namedWindow("gray", WINDOW_AUTOSIZE);
imshow("gray", gImage);

waitKey(0);
return 0;
}

我试着运行

pkg-config --modversion opencv

检查我是否安装了正确版本的 opencv,它按预期返回了“3.2.0”。如果这有任何相关性,我也正在运行 Mint 19.1(我是初学者,所以我不太了解更高级用户可能建议/做的事情)

最佳答案

#include <opencv2/imgproc.hpp>

是我所需要的。没有写在官方教程的代码中,所以我不知道我需要它。

关于c++ - 有没有办法修复编译器找不到特定的 openCV 变量/函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963385/

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