TK421
TK421

Reputation: 363

OpenCV Tutorial: Load and Display an Image (codeblocks, fedora20)

I successfully installed and linked and included OpenCV. (I know it was successful because I compiled and ran the opencv program found on this site)

So I went back to the OpenCV documentation and tutorials pages. I copied from this page the exact code below.

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(!image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}
//This is the end

(Running codeblocks on fedora20) Using Project >> Set programs' arguments I fed in "/home/Kennedy/Pictures/enterprise.bmp" without the quotes.

Since I'm using a bmp file (supported), and the file path is correct, can anyone suggest why codeblocks is spitting out

/home/Kennedy/Documents/workspace/OpenCVtest/main.cpp|21|error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope|

instead of running a lovely little first program?

For reference, I've read but not found help on this, this, and other Q&As on stackoverflow, codeblocks forum, and anywhere else I could think to look. I also saw this, but I'm not having a problem with WINDOW_AUTOSIZE.

EDIT TO ADD ANOTHER ATTEMPTED SOLUTION: I copied and pasted enterprise.bmp to the folder containing the project, removed the arguments, and replaced argv1 with "enterprise.bmp". This had no effect, I still get the same error.

Upvotes: 9

Views: 13009

Answers (2)

user4462787
user4462787

Reputation: 336

That means you're likely compiling against opencv 3.0. The symbol "CV_LOAD_IMAGE_COLOR" has been replaced with "cv::IMREAD_COLOR". Just edit the file and you should be good. It's the only deprecated symbol used in Caffe.

Upvotes: 32

sean
sean

Reputation: 51

I have the same issue when I installed ubuntu and opencv.

I tried to change the header include file as below, the problem is solved and run successfully.

But I don't know why , who can help ?

My change is comment out opencv.hpp header file and add cv.h and highgui_c.h ...

#include <opencv/cv.h>
#include <opencv2/highgui/highgui_c.h>
//#include <opencv2/opencv.hpp>

Upvotes: -1

Related Questions