[SOLVED] Frustration with OpenCV integration
-
wrote on 19 Nov 2012, 05:21 last edited by
Am stuck - after hours of trial and error - here is my request for assistance:
OS: Windows 7 64bit
QT: 4.8.3
QT Creator: 2.4.1Hava a small app created to test kalman filter in OpenCV (2.4.3). Downloaded OpenCV-2.4.3.exe and expanded into c:\opencv
To make doagnostics easier, I copied:C:\opencv\build\x86\mingw into <MyProject>\mingw
C:\opencv\modules into <MyProject>\modulesat the top of my code file:
@#include <stdio.h>
#include <iostream>
#include <vector>#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/core/core.hpp>@My PRO FIle:
@QT += network core gui opengl
TARGET = KALMAN
TEMPLATE = appInput
SOURCES += canvas.cpp
kfilter.cpp
main.cpp
mainwindow.cppHEADERS += canvas.h
kfilter.h
mainwindow.h
ui_mainwindow.hINCLUDEPATH += modules/core/include
modules/highgui/include
modules/imgproc/include
modules/features2d/include
modules/calib3d/include
modules/flann/include
modules/gpu/include
modules/legacy/include
mmodules/ml/include
modules/nonfree/include
modules/objdetect/include
modules/photo/include
modules/stitching/include
modules/ts/include
modules/videostab/include
modules/video/includeLIBS += mingw/lib/libopencv_core243.dll.a
mingw/lib/libopencv_highgui243.dll.a
mingw/lib/libopencv_imgproc243.dll.a
mingw/lib/libopencv_features2d243.dll.a
mingw/lib/libopencv_calib3d243.dll.a
mingw/lib/libopencv_calib3d243.dll.a
mingw/lib/libopencv_flann243.dll.a
mingw/lib/libopencv_gpu243.dll.a
mingw/lib/libopencv_legacy243.dll.a
mingw/lib/libopencv_ml243.dll.a
mingw/lib/libopencv_nonfree243.dll.a
mingw/lib/libopencv_objdetect243.dll.a
mingw/lib/libopencv_photo243.dll.a
mingw/lib/libopencv_stitching243.dll.a
mingw/lib/libopencv_ts243.a
mingw/lib/libopencv_videostab243.dll.a
mingw/lib/libopencv_video243.dll.a@It all compiles well, but when run (Debug or Release):
During startup program exited with code 0xc0000139
I hope someone can assist?
Kind Regards
-
Are openCV, Qt and your project built with the same compiler?
-
wrote on 19 Nov 2012, 07:29 last edited by
[SOLVED]
I update my minGW to the lates version from GNU 3.8.1 to 3.8.2 all go :-) -
wow, that was quick ;-) I thought we would have to battle with this topic, as AFAIK oCV can be nasty at times.
Anyway, good to hear you're good now.
PS. I think the most recent minGW is close to GCC 4.7, isn't it?
-
wrote on 8 Jan 2013, 17:09 last edited by
Hi,
I have the exact same problem using the kalman filter. I'd like to solve this, but I'm a beginner and I can't really figure out the solution. Could you provide more specific instructions to do this?
I mean, you update minGW and then what? You compile again the OpenCV libraries? What about Qt, isn't it supposed to work with MinGW 4.4?Thank you for your help
-
wrote on 12 Mar 2013, 12:14 last edited by
The header should look something like this:
@#ifndef Kalman_h
#define Kalman_h#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/core/core.hpp>using namespace cv;
using namespace std;class Kalman
{public:
Kalman();
QPointF calculatePrediction(QPointF);public slots:
signals:
protected:
private:
KalmanFilter KF;
Mat_<float> state;
Mat processNoise;
Mat_<float> measurement;
Mat prediction;
Mat estimated;};
#endif // Kalman_h@And the cpp something like this:
@#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/core/core.hpp>
#include <QDebug>
#include <QString>#include "Kalman.h"
using namespace cv;
using namespace std;Kalman::Kalman()
: KF(4, 2, 0, CV_32F), state(4, 1), processNoise(4, 1, CV_32F), measurement(2,1)
{
try
{
// Setup TRANSITION matrix for x,y,dx and dy
KF.transitionMatrix = *(Mat_<float>(4, 4) << 1,0,1,0, 0,0.5,0,0.5, 0,0,1,0, 0,0,0,1);
// set Measurement matrix to 0
measurement.setTo(Scalar(0));// Setup Kalman Filter KF.statePre.at<float>(0) = -1; KF.statePre.at<float>(1) = -1; KF.statePre.at<float>(2) = 0; KF.statePre.at<float>(3) = 0; setIdentity(KF.measurementMatrix); setIdentity(KF.processNoiseCov, Scalar::all(4e-4)); setIdentity(KF.measurementNoiseCov, Scalar::all(1e-1)); setIdentity(KF.errorCovPost, Scalar::all(.1)); } catch (std::exception &e) { qFatal("Error exception in Kalman constructor:\n %s", e.what()); } catch (...) { qFatal("Error unknown exception in Kalman constructor"); }
}
QPointF RCMKalman::calculatePrediction(QPointF newPosition)
{try { prediction = KF.predict(); QPointF predictPt(prediction.at<float>(0),prediction.at<float>(1)); measurement(0) = newPosition.x(); measurement(1) = newPosition.y(); QPointF measPt(measurement(0),measurement(1)); estimated = KF.correct(measurement); QPointF statePt(estimated.at<float>(0),estimated.at<float>(1)); qDebug() << "Got Mouse (Act) : " << measPt.x() << " " << measPt.y(); qDebug() << "Got Predict : " << predictPt.x() << " " << predictPt.y(); qDebug() << "Got Estimated : " << statePt.x() << " " << statePt.y(); return statePt; } catch (std::exception &e) { qFatal("Error exception in Kalman calculatePrediction:\n %s", e.what()); return QPointF(0,0); } catch (...) { qFatal("Error unknown exception in Kalman calculatePrediction"); return QPointF(0,0); }
}@
-
You need to use the same MinGW version to build every part of your program. This is because MinGW is very fragmented and prone to binary incompatibilities.