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!!
Do you build opencv using cmake ?
Thank you! Yes I did, I used cmake and VS 2017
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
are there even vs2017 prebuilt packages ?
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!! :)
"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