Ask Your Question

Revision history [back]

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

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

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

under. Code:

int main()
{
    Mat imag;

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

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