10

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?

Milan
  • 1,743
  • 2
  • 13
  • 36
CanCam
  • 111
  • 1
  • 1
  • 3
  • 2
    Please post an [MCVE] so we can see exactly what you've done - otherwise it's hard to answer. – Alan Stokes Nov 14 '15 at 10:42
  • 1
    You have not set OpenCV correctly. See [here](http://stackoverflow.com/a/31545237/5008845) to know what to include and link (here are added to a Visual Studio project, just add to you gcc command line). – Miki Nov 14 '15 at 10:53
  • 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' – CanCam Nov 14 '15 at 10:55
  • @Miki I use Ubuntu, not Windows :/ – CanCam Nov 14 '15 at 10:57
  • Yeah, I got that. But you need to include and link opencv properly. – Miki Nov 14 '15 at 10:58
  • 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 similar – Micka Nov 14 '15 at 11:02
  • Check out [here](http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/) @berriel did a nice tutorial. – Miki Nov 14 '15 at 11:13
  • Just add this header file #include "opencv2/highgui/highgui.hpp" – Sagar Patel Nov 16 '15 at 10:17

4 Answers4

8

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);
mask
  • 539
  • 1
  • 5
  • 18
  • 3
    1) you don't need `#include `, 2) you can just use `#include ` 3) without a `main` this won't work, 4) Opencv 3.0 parameter is now called `IMREAD_COLOR` – Miki Nov 14 '15 at 11:31
  • 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 libraries – CanCam Nov 14 '15 at 21:55
7
#include <opencv2/imgcodecs.hpp> 

solved the problem which contains the imread function

letsdev-cwack
  • 99
  • 4
  • 10
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

Roel Van de Paar
  • 2,111
  • 1
  • 24
  • 38
-1

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