错误:"imread"未在此范围内声明

error: ‘imread’ was not declared in this scope

本文关键字:quot 范围内 声明 imread 错误      更新时间:2023-10-16

我正在使用 https://github.com/opencv/opencv/archive/4.0.0.zip 的OpenCV 4.0 下面是代码

#include "opencv2/core.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/highgui.hpp"
using namespace std;
using namespace cv;

int main(int argc, const char* argv[]){
Mat frame0 = imread("hallo");
return 0;
}

我编译它

g++ -std=c++11 test.cpp -o test -I/home/user/opencv/modules/core/include/ -I/home/user/opencv/modules/highgui/include/ -L/home/user/opencv/build/lib -lopencv_objdetect -lopencv_features2d -lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_imgcodecs 

它抛给我错误

test.cpp: In function ‘int main(int, const char**)’:
test.cpp:11:32: error: ‘imread’ was not declared in this scope
Mat frame0 = imread("hallo");

关于如何解决它的任何方向?

#include <opencv2/imgcodecs.hpp>和使用

g++ -std=c++11 test.cpp -o test -I/home/user/opencv/modules/core/include/ -I/home/user/opencv/modules/gapi/include/ -I/home/user/opencv/modules/highgui/include/ -I/home/user/opencv/modules/imgcodecs/include/  -L/home/user/opencv/build/lib -lopencv_objdetect -lopencv_features2d -lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_imgcodecs

编译将解决问题