Visual Studio 2015 OpenCV Assertion 在 cv::imshow windows 中失败 (size.width>0 && size.height>0.cp

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

本文关键字:size gt cp height 失败 width OpenCV 2015 Studio Assertion windows      更新时间:2023-10-16

我最近一直在学习一些C ,由于某种原因,我一直在遇到相同的错误。

显然,Imshow无法找到该文件。

我的代码是

#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 filenn" ;
    }
    cv::namedWindow("test");
    cv::imshow("test",img);
    waitKey(0);
}
  • 我尝试将其与" .exe"一起放入项目文件夹中,
  • 我尝试使用"/"answers" "
  • 列出图像的整个目录
  • 我也尝试过不使用代码中的任何扩展名,但无济于事。

错误符号

感谢您的帮助:)

我总是建议这些情况相同的事情。它只需要一些横向思考。将您的代码更改为此

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

现在运行此程序,它将 create 一个称为test.txt的文件。找出该文件在系统上的位置,这是您应该放置1.png文件的地方。然后,您可以回到原始程序,确信该文件在正确的位置,其余问题都是一个不同的问题。