New to OpenCV, can't load an image

asked 2017-05-10 02:47:11 -0600

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!!

edit retag flag offensive close merge delete

Comments

Do you build opencv using cmake ?

LBerger gravatar imageLBerger ( 2017-05-10 02:49:47 -0600 )edit
1

Thank you! Yes I did, I used cmake and VS 2017

Keehnel gravatar imageKeehnel ( 2017-05-10 02:54:37 -0600 )edit

Have you build opencv with sample? I think your VS project is wrong. You should use cmake to build your project too like in this sample

LBerger gravatar imageLBerger ( 2017-05-10 03:04:07 -0600 )edit

are there even vs2017 prebuilt packages ?

berak gravatar imageberak ( 2017-05-10 03:13:07 -0600 )edit

I did build opencv with samples, and most of them don't work. How does cmake affect VS recognizing what functions are a part of the cv namespace? I can't even get my program to compile.

@berak: I'm pretty sure there aren't any VS 2017 prebuilt packages, I wish there were!! :)

Keehnel gravatar imageKeehnel ( 2017-05-11 22:48:58 -0600 )edit

"most of them don't work" don't try your own project. You have to solve this first. Go back to opencv project and clean solution and build. Give first error. I can build opencv and opencv_contrib with VS 2017 (without Eigen) : "========== Build: 350 succeeded, 0 failed, 7 up-to-date, 5 skipped =========="

And I go back to VS 2015 waiting VS 2017 update 1

LBerger gravatar imageLBerger ( 2017-05-12 00:29:50 -0600 )edit