PDA

View Full Version : cvLoadImage & realloc(): invalid pointer



cae
29th August 2013, 10:51
Hello,

i'm trying to use QtCreator + opencv, i think i have everything well installed, in fact, y can run some smalls programs. I created a Qt project with a .ui where i placed a button, and when it's clicked it calls a function that does the following:



void MainWindow::on_pushButton_clicked()
{
QFileDialog dialog(this);
dialog.setDirectory(QDir::homePath());
dialog.setFileMode(QFileDialog::ExistingFiles);
QStringList fileNames;
if (dialog.exec())
fileNames = dialog.selectedFiles();

for (int i = 0; i < fileNames.size(); i++) {
qDebug() << "file "+fileNames.at(i);
}

}

This works correctly, i can choose several files and it prints the names after on the console but.... i am trying to load each image as an IplImage like this:



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

#include <QFileDialog>
#include <QDebug>
using namespace cv;
using namespace std;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
QFileDialog dialog(this);
dialog.setDirectory(QDir::homePath());
dialog.setFileMode(QFileDialog::ExistingFiles);
QStringList fileNames;
if (dialog.exec())
fileNames = dialog.selectedFiles();

for (int i = 0; i < fileNames.size(); i++) {
qDebug() << "file "+fileNames.at(i);
IplImage* img = cvLoadImage("/home/cae/Descargas/lena.jpg");

}

}

and it doesn't work, it builds correctly, but when i run, i dont reach to see the gui, i recieve the following error:


Starting /home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV...
*** Error in `/home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV': realloc(): invalid pointer:] 0x00007f0b6faa8340 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7f576)[0x7f0b6ea08576]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0x300)[0x7f0b6ea0cda0]
/home/cae/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QListData7reallocEi+0x26)[0x7f0b6f53be46]
/home/cae/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN9QListData7prependEv+0x82)[0x7f0b6f53c012]
/home/cae/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(_ZN10QTextCodecC1Ev+0x85)[0x7f0b6f6f5be5]
/home/cae/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x2728b9)[0x7f0b6f6f98b9]
/home/cae/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5(+0x272d0d)[0x7f0b6f6f9d0d]
.
.
.
======= Memory map: ========
00400000-00407000 r-xp 00000000 08:05 541441 /home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV
00606000-00607000 r--p 00006000 08:05 541441 /home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV
00607000-00608000 rw-p 00007000 08:05 541441 /home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV
01331000-01352000 rw-p 00000000 00:00 0 [heap]
7f0b5fdb0000-7f0b5fdb3000 r-xp 00000000 08:05 1576774 /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
7f0b5fdb3000-7f0b5ffb2000 ---p 00003000 08:05 1576774 /lib/x86_64-linux-gnu/libgpg-error.so.0.8.0
.
.
.

The program has unexpectedly finished.
/home/cae/code/computerVision/build-testCV-Desktop_Qt_5_0_2_GCC_64bit-Debug/testCV exited with code 0



My .pro file:


#-------------------------------------------------
#
# Project created by QtCreator 2013-06-10T22:34:06
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = testCV
TEMPLATE = app
CONFIG += console

SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui

INCLUDEPATH+=/home/cae/OpenCV-2.4.2/include/opencv
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
LIBS += -lopencv_nonfree

i'm searching related errors to realloc(): invalid pointer & cvLoadImage, but i'm not able to find anything helpfull.... can you help me please?

Added after 1 5 minutes:

Sorry,

apparently opencv was not well installed.... i reinstalled it and now it works.

i followed this blog: http://opencvstart.blogspot.com.es/