How to fix OpenCV assertion failed error? : <p>When I try to run the code below in Visual Studio I getting an error message:</p>

<p>Unhandled exception at 0x00007FFC976DA839 in TestOpenCV.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000003DAEEFF360.</p>

<p>And the command window show this message:</p>

<p>OpenCV(4.1.0-dev) Error: Assertion failed (size.width>0 &amp;&amp; size.height>0) in cv::imshow, file C:\Users\hordon\opencv\modules\highgui\src\window.cpp, line 352</p>

<p>I can't figure out whats is wrong. My best guess is that I use a virtual Windows 10 on a Mac with Parallels Desktop and something is wrong with the path. But that would be strange since I copied the image directly next to the EXE. Any idea how to fix this?</p>

<pre><code>#include "pch.h"
#include &lt;iostream&gt;
#include &lt;opencv2/core.hpp&gt;
#include &lt;opencv2/highgui.hpp&gt;
#include &lt;opencv2/imgproc.hpp&gt;

cv::Mat image;

void myMouseCallback(int event, int x, int y, int flags, void* userdata)
{
    if (flags &amp; cv::MouseEventFlags::EVENT_FLAG_LBUTTON) {
        if (flags &amp; cv::MouseEventFlags::EVENT_FLAG_SHIFTKEY) {
            cv::rectangle(image, { x,y }, { y, x }, CV_RGB(255, (x*y) % 255, (x + y) % 255));
        } else if (flags &amp;cv::MouseEventFlags::EVENT_FLAG_ALTKEY) {
            cv::line(image, { x, y }, { y, x }, CV_RGB((y * x) % 255, (int)(sin((double)x / image.cols) * 255), (x * y * x - y) % 255));
        } else {
            cv::circle(image, { x,y }, (x + y) % 10, 0);
        }
    }

    cv::imshow("Ablak", image);
}

int main()
{
    image = cv::imread(".\\csillam.jpg");

    cv::Mat greyScale(image.rows, image.cols, CV_8UC1);
    for (int i = 0; i &lt; greyScale.rows; ++i) {
        for (int j = 0; j &lt; greyScale.cols; j++) {
            cv::Vec3b pixel = image.at&lt;cv::Vec3b&gt;(i, j);

            greyScale.at&lt;uint8_t&gt;(i, j) = (pixel[0] + pixel[1] + pixel[2]) / 3;
        }
    }
    cv::imshow("Greyscale", greyScale);

    cv::imshow("Ablak", image);
    cv::setMouseCallback("Ablak", myMouseCallback);

    cv::waitKey(0);
}
</code></pre>
