简体   繁体   English

Visual Studio 2015 OpenCV 断言在 cv::imshow windows.cpp 中失败(size.width>0 && size.height>0)

[英]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.我最近一直在学习一些 C++,但由于某种原因,我不断收到同样的错误。

Apparently, imshow isn't able to find the file.显然, imshow 无法找到该文件。

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",我试过把它和“.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 .现在运行这个程序,它会创建一个名为test.txt的文件。 Find out where that file is on your system and that's where you should put your 1.png file.找出该文件在您的系统上的位置,以及您应该将1.png文件放置的1.png 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.然后您可以返回到您的原始程序,确信该文件位于正确的位置,并且任何剩余的问题都是不同的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用 VideoCapture 和 imshow(),引发 Assertion failed (size.width&gt;0 &amp;&amp; size.height&gt;0) in cv::imshow - trying to use VideoCapture and imshow(), raises Assertion failed (size.width>0 && size.height>0) in cv::imshow 使用OpenCV断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0)Qt - Assertion failed (size.width>0 && size.height>0) Qt with OpenCV 复制图像后在imshow中断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0) - Assertion failed (size.width>0 && size.height>0) in imshow after copying image OpenCV 错误:断言失败 (size.width&gt;0 &amp;&amp; size.height&gt;0) 简单代码 - OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code opencv错误:未知函数行261中的断言失败(size.width&gt; 0 &amp;&amp; size.height&gt; 0) - opencv error: assertion failed (size.width>0 && size.height>0) in unknown function line 261 C++,OpenCV,在尝试显示图像时收到此错误“OpenCV(4.3.0)错误:断言失败(size.width&gt;0 &amp;&amp; size.height&gt;0)” - C++, OpenCV, getting this error “OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)” when trying to display image OpenCV错误:断言失败(a_size.width == len) - OpenCV Error: Assertion failed (a_size.width == len) OpenCV错误:cv :: Mat :: at中的断言失败((无符号)i0 &lt;(无符号)size.p [0]) - OpenCV Error: Assertion failed ((unsigned)i0 < (unsigned)size.p[0]) in cv::Mat::at OpenCV 断言失败 ((unsigned)(i1 * DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1] * channels())) 在 cv::Mat::at - OpenCV Assertion failed ((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())) in cv::Mat::at OpenCV错误:cvInRangeS中的断言失败(src1.size == dst.size &amp;&amp; dst.type()== CV_8U) - OpenCV Error: Assertion failed (src1.size == dst.size && dst.type() == CV_8U) in cvInRangeS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM