Unable to load image in Visual studio c++ [closed]

asked 2019-06-25 20:36:49 -0600

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

main()

{ Mat imag;

   // LOAD image
   imag = imread("D:\\image1.png",0);   // Read the file "image1.png".

   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;

}

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by LBerger
close date 2019-06-26 01:28:31.825786

Comments

1

that's pretty normal, you're a noob with no clue about relative pathes,, and your ide is playing tricks on you.

try to find the debug settings for your project, and adjust the startup path, so you program starts in the expected folder with the image.

berak gravatar imageberak ( 2019-06-26 00:28:48 -0600 )edit

@berak please help me sir, i have put the image in debug directory and also set the working directory as debug folder . but it fails, can you help me with teamviewer ?

xiejing gravatar imagexiejing ( 2019-06-26 02:15:57 -0600 )edit

can you help me with teamviewer ?

no, never, sorry.

berak gravatar imageberak ( 2019-06-26 02:36:56 -0600 )edit