6

First the code:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main( int argc, char** argv )
{
    Mat image;
    image = imread( "MyPic.jpg", CV_LOAD_IMAGE_GRAYSCALE );

    if( !image.data )
    {
        printf( "No image data \n" );
        return -1;
    }

    namedWindow( "Display Image", CV_WINDOW_AUTOSIZE);
    imshow( "Display Image", image );

    waitKey(0);

    return 0;
}    

A simple program that just loads an image with then name "MyPic.jpg" , this is an example that I found on the open CV website documentation (with small changes). It gives me these two error:

    ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
    ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope

Why is it not working? What's wrong?

Metalzero2
  • 531
  • 2
  • 6
  • 17
  • 3
    Are you using the trunk or the release version of OpenCV? If it is the former, then you are supposed to use `IMREAD_GRAYSCALE` and `WINDOW_AUTOSIZE` instead. – scap3y Mar 21 '14 at 01:39
  • I'm really sure because I'm new at this stuff (don't know terminologies that well yet). I build it, using Cmake, from source. I tried what you said (IMREAD_GRAYSCALE and WINDOW_AUTOSIZE) and it works just fine now. But when I was looking in the documentation (http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#imread) it has the release version flags. Where can I find all the changes that have been done? Have only the flags changes or functions too? – Metalzero2 Mar 21 '14 at 16:11

2 Answers2

6

I am putting my comment as answer so that others who face this issue can find the solution easily.

Are you using the trunk or the release version of OpenCV? If it is the former, then you are supposed to use IMREAD_GRAYSCALE and WINDOW_AUTOSIZE instead. The new documentation, including changes in function calls, etc. can be found in this link.

HTH

scap3y
  • 1,188
  • 10
  • 27
  • I still can't find what I'm looking for. Can you send me the link where it says that for the function "imread" the "IMREAD_GRAYSCALE" is to be used? – Metalzero2 Mar 21 '14 at 17:27
  • Can't you search it in the same place? http://docs.opencv.org/trunk/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#cv2.imread – scap3y Mar 21 '14 at 17:53
  • I did search for it and could not find it, that's why I am asking. I did find the link you send me (as you can see at my comment on my post) but here is says CV_LOAD_IMAGE_GRAYSCALE and not IMREAD_GRAYSCALE. How do I find the new flags, that's what I want to know. – Metalzero2 Mar 21 '14 at 19:21
  • Okay, in that case, just search for the definition in the source code itself. – scap3y Mar 22 '14 at 00:43
  • You found IMREAD_GRAYSCALE and WINDOW_AUTOSIZE by searching in the source code? How do I search in the source code for every single flag? – Metalzero2 Mar 23 '14 at 11:28
2

Solved this by doing the following:

  1. make sure you're using the namespace: using namespace cv;
  2. instead of using CV_LOAD_IMAGE_GRAYSCALE, try doing: cv::IMREAD_GRAYSCALE

alternatives:

Going through the opencv project you can also attempt to run a quick search with your constant and provide a numerical value instead. For example, in the case of CV_LOAD_IMAGE_GRAYSCALE, it was found to correspond to the value of 0 within the code (specifically within the file constants_c.h.

Cerulean.Source
  • 133
  • 1
  • 4
  • `cv::IMREAD_GRAYSCALE` (and in my case also `cv::IMREAD_COLOR`) worked for me! Had to change it in 2 files when trying to build caffe – M.K Sep 14 '22 at 12:13