Ask Your Question
0

Unable to load an image - Open CV not working with Visual Studio2015

asked 2017-09-10 20:09:06 -0600

Tasie gravatar image

Hi guys,

I have just set up open cv3.1.0 with visual studio 2015 on windows 10. My simple code for loading the image is as under:

   #include "opencv2\opencv.hpp"
    using namespace cv;

    int main(int argv, char** argc)
    {
        Mat test = imread("lena_color.jpg", CV_LOAD_IMAGE_UNCHANGED);
        imshow("test", test);
        waitKey();
    }

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.

edit retag flag offensive close merge delete

Comments

hi, i have tried the following modification too but it doesn't work. gives the same error :(

Mat test = imread("C:\Users\Tasie\Documents\Visual Studio 2015\Projects\opencvtest\lena_color.jpg", CV_LOAD_IMAGE_UNCHANGED);

Tasie gravatar imageTasie ( 2017-09-10 22:05:08 -0600 )edit

try: imread("C:/Users/Tasie/Documents/Visual Studio 2015/Projects/opencvtest/lena_color.jpg"

VxW gravatar imageVxW ( 2017-09-11 09:04:42 -0600 )edit

Tried that too but did not work .gives this error : "OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\build\2_4_winpack-build-win64-vc14\opencv\modules\highgui\src\window.cpp, line 261"

Tasie gravatar imageTasie ( 2017-09-11 12:08:33 -0600 )edit

hey, could you get a meaningful size of this reading mat? if it's empty, it should be the problem of imread path.

cbyzju gravatar imagecbyzju ( 2017-09-12 01:41:48 -0600 )edit

why are there 2 different opencv versions in your error messages ?

  • C:\buildslave64\win64_amdocl\master_PackSlave-win64-vc14-shared\opencv...
  • C:\build\2_4_winpack-build-win64-vc14\opencv...
berak gravatar imageberak ( 2017-09-12 08:01:04 -0600 )edit

@cbyzju I have modified the code to display the matrix as :

{
    Mat test = imread("C:\\Users\\Tashia\\Documents\\Visual Studio 2015\\Projects\\Opencv_test\\logo.png", 
        IMREAD_COLOR);

    cout << "And the matrix is " << endl << " " << test << endl << endl;

    if (test.empty())                      // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }

    waitKey();
}

but the terminal window displays this:

And the matrix is
 [ ]

Could not open or find the image

which means the image is not being loaded. I have tried jpg and png formats for images and placed them in my working directory (in the visual studio project folder). no idea what else to try.

Tasie gravatar imageTasie ( 2017-09-12 09:54:02 -0600 )edit

@berak I have tried different versions for OpenCV to see if any one of them works for me but got the same error msg for every version I tried.

Tasie gravatar imageTasie ( 2017-09-12 09:56:24 -0600 )edit

if you run your prog from your ide, it will start in the debug (or relase folder), not in your project folder

berak gravatar imageberak ( 2017-09-12 10:23:23 -0600 )edit

@Tasie what did you change in the code to work?? or any other thing to be done?? and how did you run?

anonymous1997 gravatar imageanonymous1997 ( 2019-03-27 05:25:53 -0600 )edit

@Tasie what did you change in your code ? i have got same error please give me a solution

xiejing gravatar imagexiejing ( 2019-06-20 08:40:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-09-12 10:46:20 -0600

Tasie gravatar image

Thankyou,it totally worked :) A newbie mistake!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-10 20:09:06 -0600

Seen: 4,679 times

Last updated: Sep 10 '17