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/opencv-3.2.0.www.fileniko.com/opencv-3.2.0/modules/highgui/src/window.cpp, line 304
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/ali/Downloads/opencv/opencv-3.2.0.www.fileniko.com/opencv-3.2.0/modules/highgui/src/window.cpp:304: error: (-215) size.width>0 && size.height>0 in function imshow

Press <RETURN> to close this window...
^A

Using opencv3.2 ubuntu qt

  • 1
    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 '17 at 17:17

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.