Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 481
TK421 Avatar asked Jun 26 '14 20:06

TK421


People also ask

How to Display image with OpenCV?

In order to load an image off of disk and display it using OpenCV, you first need to call the cv2. imread function, passing in the path to your image as the sole argument. Then, a call to cv2. imshow will display your image on your screen.

How do I display a JPEG image in C++?

jpg”, IMREAD_grayscale); imshow(): This function is used to display images and takes the following two arguments: winname or window name: This is the title of the window displaying the image and is of type string. image: This is the image to be displayed.

What format is the image read in using OpenCV as an array in C++ and as a list in Python?

Read a Transparent PNG or TIFF in OpenCV These images can be read in OpenCV using the IMREAD_UNCHANGED flag.

What format is the image read in OpenCV?

So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers.


1 Answers

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.

like image 86
user4462787 Avatar answered Oct 11 '22 14:10

user4462787