gpt4 book ai didi

c++ - Qt下opencv崩溃无报错

转载 作者:太空宇宙 更新时间:2023-11-04 13:51:27 25 4
gpt4 key购买 nike

我在Qt下有问题,其实我想在它(ubuntu)下使用opencv却出现了崩溃。如果我在终端下编译:

g++ pkg-config --cflags opencv example.cc -o output_file pkg-config --libs opencv

一切正常,但在 QT 下出现崩溃问题,我刚刚看到此消息错误:

开始/home/quentin/build-test_opencv-Desktop_Qt_5_2_1_GCC_64bit-Release/test_opencv...程序意外结束。/home/quentin/build-test_opencv-Desktop_Qt_5_2_1_GCC_64bit-Release/test_opencv 崩溃了

这是我的.pro:

QT       += core

QT -= gui

TARGET = test_opencv
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

CONFIG += link_pkgconfig
PKGCONFIG += opencv

SOURCES += main.cpp

INCLUDEPATH += -I /usr/local/include/opencv

LIBS += `pkg-config opencv --libs`

这是我的 main.cpp :

#include <QCoreApplication>
#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;

int main(int argc, char *argv[])
{

IplImage* img = cvLoadImage( "lena.png" );

cout << "Image WIDTH = " << img->width << endl;
cout << "Image HEIGHT = " << img->height << endl;
cvReleaseImage( &img );
return 0;


}

最佳答案

很可能 cvLoadImage 失败并返回 nullptr。你永远不会费心去检查它。

关于c++ - Qt下opencv崩溃无报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23233393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com