PDA

View Full Version : Qt run time error in using compute function of HOG descriptor



Sai Kamat
11th June 2014, 10:38
I am using Qt-Creator 5.2.0 to create a GUI to display the Image and a binary classifier to detect the object is present or absent using Dalal & triggs HOG extraction algorithm.

I am facing the mentioned Run time error & need help to solve this issue.
10406

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QDebug>
#include <opencv2/calib3d/calib3d.hpp>
//#include <opencv2/calib3d/calib3d.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/ml/ml.hpp>
#include<opencv2/objdetect/objdetect.hpp>
using namespace cv;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
};
float SVM_classifier(Mat image);


#endif // MAINWINDOW_H

mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"

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

IplImage *oMatDeltaImage = cvLoadImage("E:\\Wihart\\Car_Images\\(785).jpg",CV_LOAD_IMAGE_UNCHANGED);

Mat mat_img(oMatDeltaImage );
float oMatResult = SVM_classifier(mat_img);
// qDebug()<<oMatResult;

}

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

float SVM_classifier(Mat image)
{

resize(image, image, Size(64,128) );

HOGDescriptor extract_features;
vector<float> descriptorsValues;
descriptorsValues.resize(0.0);
vector<Point> locations;
locations.resize(0.0);
extract_features.compute( image, descriptorsValues, Size(0,0), Size(0,0), locations);

Mat feature_vector(descriptorsValues);// = Mat::zeros((descriptorsValues.size(),1));
CvSVM SVM;
SVM.load("SVM_classifier_data.xml");
float result= SVM.predict(feature_vector);
return result;
}

main.cpp


#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}

d_stranz
11th June 2014, 16:56
IplImage *oMatDeltaImage = cvLoadImage("E:\\Wihart\\Car_Images\\(785).jpg",CV_LOAD_IMAGE_UNCHANGED);

How do you know that "oMatDeltaImage" is a valid pointer? I presume that if cvLoadImage() fails, it will return a NULL pointer. You don't check the return value, you simply use it in the next line and in SVM_classifier() and assume it is OK.

The debugger would probably have found your error in less time than it took to make your post.

Malharbhatt
12th June 2014, 08:24
I tried to run this program using visual studio 10 with a qt addin-1.19 in it. The code runs fine.