Ask Your Question

error: ‘imread’ was not declared in this scope

asked 2020-02-15 00:07:53 -0500

I am using OpenCV 4.0 from Below is the code

#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;

I compile it with

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

It throws me error

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");

Any direction on how to resolve it?

edit retag flag offensive close merge delete


This is not a filename "hallo"

supra56 gravatar imagesupra56 ( 2020-02-16 11:06:54 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2020-02-15 01:11:59 -0500

berak gravatar image


#include <opencv2/imgcodecs.hpp>

in your code.

also you should not include anything from the src folder,

a proper make install should have copied the headers to


and the libs to

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-02-15 00:07:53 -0500

Seen: 366 times

Last updated: Feb 15 '20