C++ 错误:imread 不是 cv 的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33707500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:18:32  来源:igfitidea点击:

error: imread is not a member of cv

c++opencvubuntuimread

提问by CanCam

I use OpenCV 3.0 and Ubuntu 14.04. I'm trying to compile a few codes on ubuntu using opencv. I get error

我使用 OpenCV 3.0 和 Ubuntu 14.04。我正在尝试使用 opencv 在 ubuntu 上编译一些代码。我得到错误

"error: 'imread' is not a member of 'cv'"

“错误:‘imread’不是‘cv’的成员”

Due to my previous search knowledge, I tried compiling by adding "highgui.h".

由于我之前的搜索知识,我尝试通过添加“highgui.h”进行编译。

I use:

我用:

$g++ main.cpp HOG.cpp HOGFeaturesOfBlock.cpp -I/usr/local/include/opencv -lml -lcvaux -highgui -lcv -lcxcore -o featureExtractor

on terminal to compile.

在终端上编译。

Any suggest? Regards. Can.

有什么建议吗?问候。能。

回答by mask

The following commands should work. If it doesn't work you should check if you set the include/lib files correctly.

以下命令应该可以工作。如果它不起作用,您应该检查是否正确设置了包含/lib 文件。

#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv\cv.hpp>

using namespace cv;

Mat image = imread(filename, CV_LOAD_IMAGE_COLOR);

回答by letsdev-cwack

#include <opencv2/imgcodecs.hpp> 

solved the problem which contains the imread function

解决了包含 imread 函数的问题

回答by Roel Van de Paar

I found that the compile command had to be very specific (besides having added using namespace cv;in the code), with the source file having to come directly after the g++, as follows;

我发现编译命令必须非常具体(除了using namespace cv;在代码中添加),源文件必须直接在 之后g++,如下所示;

g++ test.cpp -fpermissive $(pkg-config --cflags --libs opencv) -o testbin

Replace opencvwith opencv4if that is what you use

更换opencvopencv4,如果这是你用什么

回答by Forgoys

I had a same question before. Just add #include "imgcodec.hpp", Hope this can help you

我以前也有同样的问题。补充一下#include "imgcodec.hpp",希望能帮到你