简体   繁体   中英

Visual Studio 2015 OpenCV Assertion failed (size.width>0 && size.height>0) in cv::imshow windows.cpp

I've been learning a bit of c++ lately and i keep getting the same error for some reason.

Apparently, imshow isn't able to find the file.

My codes are

#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
    cv::Mat img;
    img = imread("1.png");
    if (img.empty())
    {
        cout << "can't find da file\n\n" ;

    }
    cv::namedWindow("test");
    cv::imshow("test",img);
    waitKey(0);
}
  • I've tried putting it in the project folder along with the ".exe",
  • I tried listing the whole directory of the image using "/" and "\\"
  • I've also tried not using any extensions in the code but to no avail.

Error Signs

Thanks for helping you guys :)

I always advise the same thing for these cases. It just needs a little lateral thinking. Change your code to this

int main()
{
    ofstream test("test.txt");
    test << "I'm here!!\n";
}

Now run this program, it will create a file called test.txt . Find out where that file is on your system and that's where you should put your 1.png file. Then you can go back to your original program confident that the file is in the right place and any remaining issues are a different problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM