OpenCV 2.4.5 and Qt5 error :S

OpenCV 2.4.5 and Qt5 error :S

本文关键字:error Qt5 and OpenCV      更新时间:2023-10-16

我正试图用qt5编译第一个打开的cv程序,但当我试图编译时,我遇到了这个奇怪的错误

  Starting /home/QtContour/build-untitled-Desktop_Qt_5_0_2_GCC_64bit-Debug/untitled...
*** Error in `/home/QtContour/build-untitled-Desktop_Qt_5_0_2_GCC_64bit-Debug/untitled': realloc(): invalid pointer: 0x00007f64e3750340 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7f576)[0x7f64e26b0576]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0x300)[0x7f64e26b4da0]
/home//Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QListData7reallocEi+0x26)[0x7f64e31e3e46]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QListData7prependEv+0x82)[0x7f64e31e4012]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN10QTextCodecC1Ev+0x85)[0x7f64e339dbe5]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x2728b9)[0x7f64e33a18b9]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x272d0d)[0x7f64e33a1d0d]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN10QTextCodec14codecForLocaleEv+0x32)[0x7f64e339d592]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZNK7QString11toLocal8BitEv+0x19)[0x7f64e3211bd9]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x80702)[0x7f64e31af702]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x7e07c)[0x7f64e31ad07c]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x7e19a)[0x7f64e31ad19a]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZNK14QMessageLogger5fatalEPKcz+0xa9)[0x7f64e31ad8c9]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QMetaType22registerNormalizedTypeERK10QByteArrayPFvPvEPFS3_PKvES5_PFS3_S3_S7_Ei6QFlagsINS_8TypeFlagEEPK11QMetaObject+0x48a)[0x7f64e3361bba]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QMetaType12registerTypeEPKcPFvPvEPFS2_PKvES4_PFS2_S2_S6_Ei6QFlagsINS_8TypeFlagEEPK11QMetaObject+0x61)[0x7f64e3361c51]
/home/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QMetaType12registerTypeEPKcPFvPvEPFS2_PKvE+0x2a)[0x7f64e3361cea]
/usr/lib/x86_64-linux-gnu/libQtGui.so.4(+0x1b995e)[0x7f64ddf0e95e]
/lib64/ld-linux-x86-64.so.2(+0xf876)[0x7f64e4679876]
/lib64/ld-linux-x86-64.so.2(+0xf930)[0x7f64e4679930]
/lib64/ld-linux-x86-64.so.2(+0x168a)[0x7f64e466b68a]
======= Memory map: ========
00400000-00405000 r-xp 00000000 08:01 7604445                            /home/QtContour/build-untitled-Desktop_Qt_5_0_2_GCC_64bit-Debug/untitled
00604000-00605000 r--p 00004000 08:01 7604445                            /home/QtContour/build-untitled-Desktop_Qt_5_0_2_GCC_64bit-Debug/untitled
00605000-00606000 rw-p 00005000 08:01 7604445                            /home/QtContour/build-untitled-Desktop_Qt_5_0_2_GCC_64bit-Debug/untitled
01890000-018b1000 rw-p 00000000 00:00 0                                  [heap]
7f64d40a5000-7f64d40a8000 r-xp 00000000 08:01 42208894                   /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
7f64d40a8000-7f64d42a7000 ---p 00003000 08:01 42208894                   /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
7f64d42a7000-7f64d42a8000 r--p 00002000 08:01 42208894                   /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
7f64d42a8000-7f64d42a9000 rw-p 00003000 08:01 42208894                   /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
7f64d42a9000-7f64d42ad000 r-xp 00000000 08:01 42209011                   /lib/x86_64-linux-gnu/libuuid.so.1.3.0 ... ....(much more)

我的主要.cpp是

#include "mainwindow.h"
#include <QApplication>
#include <opencv/cv.h>
//#include <opencv2/highgui/highgui.hpp>
#include"highgui.h"
using namespace cv;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    Mat frame;
    VideoCapture cap(0);
     if(cap.isOpened()){
       // check if we succeeded
      namedWindow("normal",1);
      for(;;)
      {
          cap >> frame; // get a new frame from camera
          imshow("nomral",frame);
          if(waitKey(30) >= 0) break;
      }
    }
 return a.exec();
}

我的项目属性是

#-------------------------------------------------
#
# Project created by QtCreator 2013-07-02T09:42:06
#
#-------------------------------------------------
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app

SOURCES += main.cpp
        mainwindow.cpp
HEADERS  += mainwindow.h
FORMS    += mainwindow.ui

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += opencv

我不知道是谁造成了这个问题,这是我有生以来第一次看到它我希望你能帮我

无论如何都要感谢

使用cmake时,请确保取消选中WITH_QT。Opencv中使用的内部版本(Qt4.0)可能会与QT Creator(QT 5.0)发生冲突这就是我解决问题的方法。

只需清除cmake缓存,取消选中WITH_QT(可能还有WITH_TBB),然后确保删除以前的opencv构建,然后重建opencv。轰,现在它工作了!

我遇到了同样的问题,我搜索了整个上午,并通过重新安装OpenCV来解决。我的opencv是2.4.9版本,构建在Ubuntu 12.04系统上,后来我使用Linux安装程序安装了QT创建者。QT创建者的版本是基于QT 5.3.1的3.1.2。我的OpenCV安装在自定义路径上。我刚刚删除了构建文件夹

cd opencv-2.4.9
rm -r build

我只是在cmake 中重新构建了没有-D WITH_QT标志的OpenCV

mkdir build
cd build
cmake -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install

make中的-j4标志表示使4个内核并行。魔术发生了,代码工作了!它不起作用的原因是,当使用cmake WITH_QT标志时,系统会构建opencv使用qt的系统默认版本,该版本与qt是从网站上下载的。然而,要使其发挥作用,我们必须拥有正确版本的QT。根据我的经验,我们不必解开WITH_TBB。