Ask Your Question

Revision history [back]

New to OpenCV, can't load an image

Hi! I am new to OpenCV and trying to follow the tutorial to load an image. However, Mat image, namedWindow, imshow, WINDOW_AUTOSIZE, and waitKey are not found in the cv namespace.

I have #included opencv\core.hpp, opencv2\imgcodecs.hpp, opencv2\highgui.hpp, opencv2\opencv.hpp, and opencv2\cv.hpp.

So far I have tried linking $(OPENCV_DIR)\lib, using namespace cv, and adding " CV_ ", " cv:: " and " cv_ " before each command.

The tutorial says to use this code:

Mat image;
image = imread(imageName.c_str(), IMREAD_COLOR);

if( image.empty() ) 
{
     cout <<  "Could not open or find the image" << std::endl ;
     return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );               

waitKey(0);

//I have found that this code will fix all but the " image " problem:

Mat image = imread(imageName.c_str(), IMREAD_COLOR);// " Mat " must be on the same line as " imread "

if( image.empty() )         // " image " is underlined here
{
     cout <<  "Could not open or find the image" << std::endl ;
     return -1;
}
const std::string& windowName("Display Window");      // Must be declared first to work
void namedWindow(int windowName, int WINDOW_AUTOSIZE );// Must have the "void" and "int" types defined
void imshow(int windowName, int image );            // Also must have types, and " image " is ok here

int waitKey(0);                              // Must have int type

I am using OpenCV 3.2 on a clean Windows 10 computer with VS 2017 Enterprise.

Thanks for your help!!