How to resolve an error: imread is not a member of cv?
Asked Answered
T

4

11

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

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

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

I use:

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

on the terminal to compile.

Any suggestions?

Targett answered 14/11, 2015 at 10:40 Comment(8)
Please post an minimal reproducible example so we can see exactly what you've done - otherwise it's hard to answer.Kalinda
You have not set OpenCV correctly. See here to know what to include and link (here are added to a Visual Studio project, just add to you gcc command line).Lillian
Okay, I'm trying to extract features form depth images in main.cpp I have also readData.cpp which is invoked in main. cpp in which I used imread when I tried to compile I get readData.cpp:error: 'imread' is not a member of 'cv'Targett
@Lillian I use Ubuntu, not Windows :/Targett
Yeah, I got that. But you need to include and link opencv properly.Lillian
in opencv3 afaik imread isnt part of highgui anymore. try to find the right module or include the all-in-one-header, opencv.hpp or similarRacialism
Check out here @berriel did a nice tutorial.Lillian
Just add this header file #include "opencv2/highgui/highgui.hpp"Trash
C
9

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

#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);
Centiliter answered 14/11, 2015 at 11:18 Comment(2)
1) you don't need #include <opencv\cv.hpp>, 2) you can just use #include <opencv2/opencv.hpp> 3) without a main this won't work, 4) Opencv 3.0 parameter is now called IMREAD_COLORLillian
I included those headers to my code, but this time I get another error, /usr/bin/ld cannot find -lml and same error for other librariesTargett
H
8
#include <opencv2/imgcodecs.hpp> 

solved the problem which contains the imread function

Heraldry answered 7/2, 2020 at 14:8 Comment(0)
W
0

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;

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

Replace opencv with opencv4 if that is what you use

Waltman answered 11/10, 2019 at 6:5 Comment(0)
H
-1

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

Horrified answered 17/10, 2019 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.