简体   繁体   English

运行时opencv(QT)中的空指针

[英]null pointer in opencv (QT) when running

Hello i have a Macbook pro with osx 10.7. 您好,我有一个Macbook Pro,带有osx 10.7。 I just installed Qt (nokia), opencv, cmake. 我刚刚安装了Qt(诺基亚),opencv,cmake。 I have never worked with any of those . 我从未与任何人合作过。 So i started my first tutorial. 所以我开始了我的第一个教程。 I created a new QT Gui application. 我创建了一个新的QT Gui应用程序。 I changed my main.cpp to : 我将main.cpp更改为:

#include <QtGui/QApplication>
#include <opencv/cv.h>
#include <opencv/highgui.h> 
#include "mainwindow.h"

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   MainWindow w;
   w.show();

   IplImage* img = 0;
   img = cvLoadImage("cat.jpg");
   cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
   cvShowImage("Example1", img);
   cvWaitKey(0);
   cvReleaseImage(&img);
   cvDestroyWindow("Example1");

   return a.exec();

} }

I also changed my .pro file: 我还更改了.pro文件:

QT       += core gui

TARGET = untitled1
TEMPLATE = app


INCLUDEPATH = /usr/local/include

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

LIBS += -lm -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc

FORMS    += mainwindow.ui

for the rest : 对于其余的 :

the cat.jpg is in the qt project folder (next to main.cpp) cat.jpg位于qt项目文件夹(位于main.cpp旁边)

Now when i build this and run it. 现在,当我构建并运行它时。 i get this error: 我收到此错误:

Starting /Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS/untitled1...
OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /Users/olivierjanssens/source/OpenCV-2.3.1/modules/core/src/array.cpp, line 2382
terminate called throwing an exceptionThe program has unexpectedly finished.
/Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS/untitled1 exited with code 0

The window opens but then it crashes and no image is shown. 窗口打开,但随后崩溃,没有图像显示。

What am i doing wrong ? 我究竟做错了什么 ?

cat.jpg is probably not in the right directory. cat.jpg可能不在正确的目录中。

If you don't supply a path it searches the current directory, which is probably /Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug or /Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS . 如果您没有提供路径,它将搜索当前目录,该目录可能是/Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug /Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS/Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug /Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS/Users/olivierjanssens/untitled1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/untitled1.app/Contents/MacOS The directory with main.cpp in it isn't searched. 不搜索包含main.cpp的目录。

Try supplying a full path to cvLoadImage() (something like "/Users/olivierjanssens/untitled1/cat.jpg" ) 尝试提供"/Users/olivierjanssens/untitled1/cat.jpg" cvLoadImage()的完整路径(例如"/Users/olivierjanssens/untitled1/cat.jpg"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM