Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open CV flags dont work

Tags:

c++

opencv

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?

like image 450
Jim Avatar asked Oct 01 '22 06:10

Jim


2 Answers

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

like image 98
scap3y Avatar answered Oct 13 '22 11:10

scap3y


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.

like image 27
Cerulean.Source Avatar answered Oct 13 '22 11:10

Cerulean.Source