运行时opencv(QT)中的空指针
您好,我有一台 Macbook pro,操作系统为 osx 10.7。我刚刚安装了Qt(诺基亚)、opencv、cmake。我从未与其中任何一个合作过。所以我开始了我的第一个教程。我创建了一个新的 QT Gui 应用程序。我将 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();
}
我还更改了我的 .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
其余部分:
cat.jpg 位于 qt 项目文件夹中(main.cpp 旁边)
现在,当我构建并运行它时。我收到此错误:
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
窗口打开,但随后崩溃并且没有显示图像。
我做错了什么?
Hello i have a Macbook pro with osx 10.7. I just installed Qt (nokia), opencv, cmake. I have never worked with any of those . So i started my first tutorial. I created a new QT Gui application. I changed my main.cpp to :
#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:
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)
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cat.jpg
可能不在正确的目录中。如果您不提供路径,它将搜索当前目录,可能是
/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
。不会搜索其中包含main.cpp
的目录。尝试提供
cvLoadImage()
的完整路径(例如"/Users/olivierjanssens/untitled1/cat.jpg"
)cat.jpg
is probably not in the right directory.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
. The directory withmain.cpp
in it isn't searched.Try supplying a full path to
cvLoadImage()
(something like"/Users/olivierjanssens/untitled1/cat.jpg"
)