1. 程式人生 > >OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\builds\master_

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\builds\master_

出現這樣的錯誤,通常是因為自己圖片路徑有問題, 工程中當下目錄也沒有圖片

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\highgui\src\window.cpp, line 271

解決辦法:

方法1,將圖片放在工程目錄下,新增現有項,如圖

Mat img = imread("my.jpg");

方法2,給出絕對路徑

Mat img = imread("F:\opencv\ConsoleApplication1\ConsoleApplication1\my.jpg");改正為:

Mat img = imread("F:\\opencv\\ConsoleApplication1\\ConsoleApplication1\\my.jpg");