OpenCV imread() 问题

OpenCV imread() 问题

我最近安装了 OpenCV,但无法使用imread()

这是我的代码

#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;
}

这是我.pro在 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

这是我收到的:

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

使用opencv3.2 ubuntu qt

答案1

这条评论提供了正确的解决方案:

那么,究竟发生了什么?我猜你的文件路径无效(应该是“ /home/ali/opencv/lena.png”——注意前面的/)

钢铁司机 7月30日 17:17

我改变了路径并且它起作用了。

相关内容