1. 程式人生 > >OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code

OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code

This error means that you are trying to show an empty image. When you load the image with imshow, this is usually caused by:

  1. The path of your image is wrong (in Windows escape twice directory delimiters, e.g. imread("C:\path\to\image.png") should be: imread("C:\\path\\to\\image.png")
    , or imread("C:/path/to/image.png"));
  2. The image extension is wrong. (e.g. ".jpg" is different from ".jpeg");
  3. You don't have the rights to access the folder.

A simple workaround to exclude other problems is to put the image in your project dir, and simply pass to imread the filename (imread("image.png")

).

Remember to add waitKey();, otherwise you won't see anything.

https://stackoverflow.com/questions/31341845/opencv-error-assertion-failed-size-width0-size-height0-simple-code