Unable to load an image - Open CV not working with Visual Studio2019
Hi guys,
I have just set up open cv4.1.0 with visual studio 2019 on windows 10. My simple code for loading the image is as under. Code:
int main()
{
Mat imag;
// LOAD image
imag = imread("D:\\image2.png"); // Read the file "image.jpg".
//This file "image.jpg" should be in the project folder.
//Else provide full address : "D:/images/image.jpg"
if(imag.empty() ) // Check for invalid inputf
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
//DISPLAY image
namedWindow("Window1", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Window1", imag); // Show our image inside it.
//SAVE image
imwrite("result1.jpg",imag);// it will store the image in name "result.jpg"
waitKey(5000); // Wait for a keystroke in the window
return 0;
}
When i build this code and run it, an empty image is momentarily displayed and I get this error in the terminal window
"OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\buildslave64\win64_amdocl\master_PackSlave-win64-vc14-shared\opencv\modules\highgui\src\window.cpp, line 281"
I have placed my image in the active directory so i have no clue why it is not being accessed
noobs always fail at relative image paths, it's not visual studio's fault, but yours.
start with an absolute path.
relevant is the dir, where your program starts (e.g. the debug or release folder)
what means absolute path?
^^ please look it up !
@berak i already tried to put the image in debug folder , but also failed
you can also set the working directory from the project's debug settings
again, try harder. there is no bug, there's just you and the file system.
@berak I am sorry but can you help me with teamviewer ?
no, sorry.
@berak Ok no problem . so i put the image in the debug folder and then using its absolute path in code, but fails . What should i do in working directory in Project setting ?
@berak I have done with all possible options what i can try with , but it fails always, absolute path in code to the image file , also set the debug folder as working directory . wrong bad. What is the problem ? can you help me once more ?