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

发布于 2024-12-10 08:55:09 字数 1619 浏览 2 评论 0原文

您好,我有一台 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城月光淡如水﹏ 2024-12-17 08:55:09

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 with main.cpp in it isn't searched.

Try supplying a full path to cvLoadImage() (something like "/Users/olivierjanssens/untitled1/cat.jpg")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文