Celeb Glow
news | March 23, 2026

OpenCV imread() problem

I have installed OpenCV lately and I cannot use imread().

This is my code

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{ Mat i=imread("home/ali/opencv/lena.png",1); namedWindow("a",WINDOW_FULLSCREEN); imshow("a",i); waitKey(0); return 0;
}

and this is my .pro file in Qt

QT += core
QT -= gui
CONFIG += c++11
TARGET = opencv
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_imgcodecs
SOURCES += main.cpp

this is what I receive:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/ali/Downloads/opencv/ line 304
terminate called after throwing an instance of 'cv::Exception' what(): /home/ali/Downloads/opencv/ error: (-215) size.width>0 && size.height>0 in function imshow
Press <RETURN> to close this window...
^A

Using opencv3.2 ubuntu qt

1

1 Answer

This comment provided the correct solution:

So - what happens, exactly? My guess is that your filepath is invalid (it needs to be "/home/ali/opencv/lena.png" - note the leading /)

steeldriver Jul 30 at 17:17

I changed the path and it worked.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy