diff --git a/TrackerPlugin_PupilDiam.cpp b/TrackerPlugin_EyeTracker.cpp similarity index 85% rename from TrackerPlugin_PupilDiam.cpp rename to TrackerPlugin_EyeTracker.cpp index 74f7914..d3f0681 100644 --- a/TrackerPlugin_PupilDiam.cpp +++ b/TrackerPlugin_EyeTracker.cpp @@ -1,6 +1,6 @@ -#include "TrackerPlugin_PupilDiam.h" +#include "TrackerPlugin_EyeTracker.h" -TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) +TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent) { ui = new Ui::TrackerPlugin_PupilDiam; trackerWorker = new TrackerWorker(); @@ -38,7 +38,6 @@ TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) uiSliders_Size.push_back(ui->Slider_Size_1); uiSliders_Size.push_back(ui->Slider_Size_2); - uiLineEdits.push_back(ui->lineEdit_PupilMinArea); uiLineEdits.push_back(ui->lineEdit_PupilMaxArea); uiLineEdits.push_back(ui->lineEdit_CorneaMinArea); @@ -49,10 +48,19 @@ TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) uiPlots.at(0)->setAxisTitle(0, "Pupil x [px]"); uiPlots.at(1)->setAxisTitle(0, "Pupil y [px]"); - uiPlots.at(2)->setAxisTitle(0, "Cornea x [px]"); - uiPlots.at(3)->setAxisTitle(0, "Cornea y [px]"); - uiPlots.at(4)->setAxisTitle(0, "Pupil diam [px]"); + uiPlots.at(2)->setAxisTitle(0, "CR x [px]"); + uiPlots.at(3)->setAxisTitle(0, "CR y [px]"); + uiPlots.at(4)->setAxisTitle(0, "Pupil Ø [px]"); + +// pLineH.setLine(0,0,100,100); +// pLineV.setLine(0,0,0,0); +// cLineH.setLine(0,0,0,0); +// cLineV.setLine(0,0,0,0); +// cameraScene->addLine(pLineH); +// cameraScene->addLine(pLineV); +// cameraScene->addLine(cLineH); +// cameraScene->addLine(cLineV); /*Prepare rects*/ for(int i=0;i<2;i++){ @@ -67,7 +75,6 @@ TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) } connect(signalMapperPosition, SIGNAL(mapped(int)), this, SLOT(onItemPositionChanged(int))); - /*Prepare curves*/ for(int i=0;ilineEdit->setValidator(intValidator); - /*Connection TrackingGui - TrackingWorker*/ connect(this, SIGNAL(thresholdChanged(int, int)), trackerWorker, SLOT(onThresholdChanged(int, int))); // //connect(ui->widget_trackingGui, SIGNAL(roiChanged(int, QRectF)), trackingWorker, SLOT(onRoisChanged(int, QRectF))); @@ -135,16 +141,16 @@ TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) connect(this, SIGNAL(sizeChanged(int, QSize)), trackerWorker, SLOT(onSizeChanged(int, QSize))); connect(this, SIGNAL(areaContraintsChanged(int,int)), trackerWorker, SLOT(onAreaConstraintsChanged(int,int))); connect(ui->checkBox_showBinary, SIGNAL(clicked(bool)), trackerWorker, SLOT(onShowBinary(bool))); -// connect(trackerWorker, SIGNAL(trackingResult(QVector)), this, SLOT(onTrackingResult(QVector))); - connect(trackerWorker, SIGNAL(trackingResult(TrackingResults)), this, SLOT(onTrackingResult(TrackingResults))); + connect(trackerWorker, SIGNAL(trackingResult(std::vector)), this, SLOT(onTrackingResult(std::vector))); +// connect(trackerWorker, SIGNAL(trackingResult(TrackingResults)), this, SLOT(onTrackingResult(TrackingResults))); } -QObject *TrackerPlugin_PupilDiam::worker() +QObject *TrackerPlugin_EyeTracker::worker() { return trackerWorker; } -void TrackerPlugin_PupilDiam::initializeUI(QLayout *layout, QGraphicsScene *cameraScene, QSize cameraResolution) +void TrackerPlugin_EyeTracker::initializeUI(QLayout *layout, QGraphicsScene *cameraScene, QSize cameraResolution) { this->cameraResolution = cameraResolution; layout->addWidget(this); @@ -169,45 +175,28 @@ void TrackerPlugin_PupilDiam::initializeUI(QLayout *layout, QGraphicsScene *came } } - - -void TrackerPlugin_PupilDiam::onTrackingResult(TrackingResults result) +void TrackerPlugin_EyeTracker::onTrackingResult(std::vector result) { - int nPlots = 5; - - /*window is full - stop */ - if(frameCount>wndLength){ - for(int i=0;ipop_front(); - } - } - - rectSamples.at(0)->push_back(QPointF(t, result.cPupil.x)); - rectSamples.at(1)->push_back(QPointF(t, result.cPupil.y)); - rectSamples.at(2)->push_back(QPointF(t, result.cCornea.x)); - rectSamples.at(3)->push_back(QPointF(t, result.cCornea.y)); - rectSamples.at(4)->push_back(QPointF(t, result.pDiam)); - - - for(int i = 0; i< nPlots; i++){ + for(int i = 0; i< rectSamples.size(); i++){ + if(frameCount>wndLength)/*window is full - stop */ + rectSamples.at(i)->pop_front(); + rectSamples.at(i)->push_back(QPointF(t, result.at(i))); rectData.at(i)->setSamples(*rectSamples.at(i)); curves.at(i)->setData(rectData.at(i)); } - ui->qwtPlot_1->replot(); ui->qwtPlot_2->replot(); ui->qwtPlot_3->replot(); ui->qwtPlot_4->replot(); ui->qwtPlot_5->replot(); + t++; frameCount++; - } -void TrackerPlugin_PupilDiam::onCheckBoxClicked(int index) +void TrackerPlugin_EyeTracker::onCheckBoxClicked(int index) { - bool isVisible = !uiPlots.at(index)->isVisible(); switch ( index ){ @@ -225,18 +214,15 @@ void TrackerPlugin_PupilDiam::onCheckBoxClicked(int index) uiPlots.at(index)->setVisible(isVisible); - - - } -void TrackerPlugin_PupilDiam::onThreshSliderMoved(int index) +void TrackerPlugin_EyeTracker::onThreshSliderMoved(int index) { float value = uiSliders.at(index)->value(); emit(thresholdChanged(index, value)); } -void TrackerPlugin_PupilDiam::onSizeSliderMoved(int index) +void TrackerPlugin_EyeTracker::onSizeSliderMoved(int index) { float value = uiSliders_Size.at(index)->value(); if((rectItems.at(index)->pos().x() + maxRectWidth*value < cameraScene->width()) & @@ -247,7 +233,7 @@ void TrackerPlugin_PupilDiam::onSizeSliderMoved(int index) } } -void TrackerPlugin_PupilDiam::on_lineEdit_editingFinished() +void TrackerPlugin_EyeTracker::on_lineEdit_editingFinished() { wndLength = ui->lineEdit->text().toDouble(); for(int i=0;itext().toInt())); } -void TrackerPlugin_PupilDiam::onItemPositionChanged(int index) +void TrackerPlugin_EyeTracker::onItemPositionChanged(int index) { if(rectItems.at(index)->pos().x() < 0){ rectItems.at(index)->setX(0); diff --git a/TrackerPlugin_PupilDiam.h b/TrackerPlugin_EyeTracker.h similarity index 88% rename from TrackerPlugin_PupilDiam.h rename to TrackerPlugin_EyeTracker.h index e60a097..44b7e3e 100644 --- a/TrackerPlugin_PupilDiam.h +++ b/TrackerPlugin_EyeTracker.h @@ -3,7 +3,7 @@ #include "TrackerInterface.h" #include "TrackerWorker.h" -#include "ui_TrackerPlugin_PupilDiam.h" +#include "ui_TrackerPlugin_EyeTracker.h" #include #include #include @@ -27,22 +27,19 @@ namespace Ui { class TrackerPlugin_PupilDiam; } -class TrackerPlugin_PupilDiam : public QWidget, public TrackerInterface +class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.PylonRecorder.TrackerInterface") Q_INTERFACES(TrackerInterface) public: - explicit TrackerPlugin_PupilDiam(QObject *parent = 0); + explicit TrackerPlugin_EyeTracker(QObject *parent = 0); QObject *worker(); void initializeUI(QLayout* guiTargetLayout, QGraphicsScene* cameraScene, QSize cameraResolution); TrackerWorker* trackerWorker; QSize cameraResolution; -public slots: - void onFrameGrabbed(cv::Mat); - private: Ui::TrackerPlugin_PupilDiam *ui; QGraphicsScene* cameraScene; @@ -51,6 +48,11 @@ public slots: QVector plotPens; QVector rectPens; + QLine pLineV; + QLine pLineH; + QLine cLineH; + QLine cLineV; + QVector*> rectSamples; QVector rectData; QVector curves; @@ -76,7 +78,7 @@ public slots: QSignalMapper* signalMapperLineEdit; private slots: - void onTrackingResult(TrackingResults result); + void onTrackingResult(std::vector); void onCheckBoxClicked(int); void onThreshSliderMoved(int); void onSizeSliderMoved(int); diff --git a/TrackerPlugin_EyeTracker.pro b/TrackerPlugin_EyeTracker.pro new file mode 100644 index 0000000..99bf745 --- /dev/null +++ b/TrackerPlugin_EyeTracker.pro @@ -0,0 +1,62 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-10-24T11:57:07 +# +#------------------------------------------------- + +TEMPLATE = lib +CONFIG += plugin +QT += widgets +TARGET = $$qtLibraryTarget(TrackerPlugin_EyeTracker) +DESTDIR = ../../../../src/build/plugins +CONFIG += c++11 + + +SOURCES += \ + TrackerWorker.cpp \ + TrackerPlugin_EyeTracker.cpp + +HEADERS += \ + TrackerWorker.h \ + NotifyingQGraphicsRectItem.h \ + TrackerPlugin_EyeTracker.h + +INCLUDEPATH += ../../../src/ + +win32 { + INCLUDEPATH += "D:\\opencv\\build_vc12\\install\\include" + + CONFIG(debug,debug|release) { + LIBS += -L"D:\\opencv\\build_vc12\\install\\x64\\vc12\\lib" \ + -lopencv_core310 \ + -lopencv_highgui310 \ + -lopencv_imgproc310 \ + -lopencv_features2d310 \ + -lopencv_videoio310 \ + -lopencv_video310 \ + -lopencv_videostab310 \ + } + + CONFIG(release,debug|release) { + DEFINES += QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT + LIBS += -L"D:\\opencv\\build_vc12\\install\\x64\\vc12\\lib" \ + -lopencv_core310 \ + -lopencv_highgui310 \ + -lopencv_imgproc310 \ + -lopencv_features2d310 \ + -lopencv_videoio310 \ + -lopencv_video310 \ + -lopencv_videostab310 \ + } + + INCLUDEPATH += "C:/Qwt-6.1.3/include" + LIBS += -L"C:/Qwt-6.1.3/lib" \ + -lqwt +} + +unix{ + CONFIG += qwt +} + +FORMS += \ + TrackerPlugin_EyeTracker.ui diff --git a/TrackerPlugin_EyeTracker.ui b/TrackerPlugin_EyeTracker.ui new file mode 100644 index 0000000..aff21a1 --- /dev/null +++ b/TrackerPlugin_EyeTracker.ui @@ -0,0 +1,366 @@ + + + TrackerPlugin_PupilDiam + + + + 0 + 0 + 610 + 909 + + + + Form + + + + + + 0 + + + + + 0 + + + + + Pupil Diameter + + + true + + + + + + + + 0 + 100 + + + horizontalLayoutWidget + + + + + + + + 0 + + + + + Pupil Y + + + true + + + + + + + + 0 + 100 + + + + + + + + + + 0 + + + + + Pupil X + + + true + + + + + + + + 0 + 100 + + + + + + + + + + 0 + + + + + Cornea Y + + + true + + + + + + + + 0 + 100 + + + + + + + + + + 0 + + + + + Cornea X + + + true + + + + + + + + 0 + 100 + + + + + + + + + + + + Qt::Horizontal + + + + + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + 0.010000000000000 + + + 1.000000000000000 + + + 2 + + + 0 + + + 1.000000000000000 + + + Qt::Horizontal + + + + + + + 255.000000000000000 + + + Qt::Horizontal + + + + + + + 50000 + + + + + + + Pupil min Area + + + + + + + Pupil max Area + + + + + + + 0 + + + + + + + + + Qt::Vertical + + + + + + + 0 + + + + + Cornea max Area + + + + + + + 0.010000000000000 + + + 1.000000000000000 + + + 2 + + + 0 + + + 1.000000000000000 + + + Qt::Horizontal + + + + + + + 50000 + + + + + + + Cornea min Area + + + + + + + 255.000000000000000 + + + Qt::Horizontal + + + + + + + 0 + + + + + + + + + + + 0 + + + + + Window width [fms]: + + + + + + + 200 + + + + + + + Binary + + + + + + + + + + QwtPlot + QFrame +
qwt_plot.h
+ 1 +
+ + QwtSlider + QWidget +
qwt_slider.h
+
+
+ + +
diff --git a/TrackerPlugin_PupilDiam.pro b/TrackerPlugin_PupilDiam.pro deleted file mode 100644 index 9f870e7..0000000 --- a/TrackerPlugin_PupilDiam.pro +++ /dev/null @@ -1,38 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2016-10-24T11:57:07 -# -#------------------------------------------------- - -TEMPLATE = lib -CONFIG += plugin -QT += widgets -TARGET = $$qtLibraryTarget(TrackerPlugin_pupilDiam) -DESTDIR = ../../../../src/build/plugins -CONFIG += c++11 - - -SOURCES += \ - TrackerPlugin_PupilDiam.cpp \ - TrackerWorker.cpp - -HEADERS += \ - TrackerPlugin_PupilDiam.h \ - TrackerWorker.h \ - NotifyingQGraphicsRectItem.h \ - TrackingResults.h - -INCLUDEPATH += ../../../../src/ - -win32 { - INCLUDEPATH += "C:/Qwt-6.1.3/include" - LIBS += -L"C:/Qwt-6.1.3/lib" \ - -lqwt -} - -unix{ - CONFIG += qwt -} - -FORMS += \ - TrackerPlugin_PupilDiam.ui diff --git a/TrackerPlugin_PupilDiam.ui b/TrackerPlugin_PupilDiam.ui deleted file mode 100644 index ae46d20..0000000 --- a/TrackerPlugin_PupilDiam.ui +++ /dev/null @@ -1,416 +0,0 @@ - - - TrackerPlugin_PupilDiam - - - - 0 - 0 - 610 - 909 - - - - Form - - - - - - 0 - - - - - - 0 - 150 - - - - - - - - - 0 - 150 - - - - - - - - 0 - - - - - Cornea Y - - - true - - - - - - - - - Min Area - - - - - - - 0 - - - - - - - - - 0 - - - - - - - Max Area - - - - - - - 50000 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 20 - - - - - - - - 0 - - - - - Pupil X - - - true - - - - - - - 0 - - - - - - - - 0.010000000000000 - - - 1.000000000000000 - - - 2 - - - 0 - - - 1.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 150 - - - - - - - - 0 - - - - - Pupil Y - - - true - - - - - - - - - Min Area - - - - - - - 0 - - - - - - - - - 0 - - - - - Max Area - - - - - - - 50000 - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - - - - - Cornea X - - - true - - - - - - - 0 - - - - - - - - 0.010000000000000 - - - 1.000000000000000 - - - 2 - - - 0 - - - 1.000000000000000 - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 150 - - - - - - - - 0 - - - - - Pupil Diameter - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Qt::Horizontal - - - - - - - 0 - - - - - Binary - - - - - - - Window width [fms]: - - - - - - - 200 - - - - - - - - - - QwtPlot - QFrame -
qwt_plot.h
- 1 -
- - QwtSlider - QWidget -
qwt_slider.h
-
-
- - -
diff --git a/TrackerWorker.cpp b/TrackerWorker.cpp index 6e51efd..ece6758 100644 --- a/TrackerWorker.cpp +++ b/TrackerWorker.cpp @@ -7,8 +7,6 @@ TrackerWorker::TrackerWorker(QObject* parent) { qRegisterMetaType < QVector >("QVectorFloat"); - qRegisterMetaType("TrackingResults"); - rois.push_back(QRect(0,0,100,100)); rois.push_back(QRect(0,0,100,100)); @@ -28,10 +26,9 @@ void TrackerWorker::onFrameGrabbed(Mat src) int cMinArea = areaConstraints.at(2); int cMaxArea = areaConstraints.at(3); - TrackingResults eyeTrackingResult; - eyeTrackingResult.cCornea = Point(0,0); - eyeTrackingResult.cPupil = Point(0,0); - eyeTrackingResult.pDiam = 0; + Point cCornea(0,0); + Point cPupil(0,0); + double pDiam = 0; std::vector rgb; split(src, rgb); @@ -59,8 +56,8 @@ void TrackerWorker::onFrameGrabbed(Mat src) if(pContour.size()>4){ /*Determine centroid by fitting an ellipse*/ pRect = fitEllipse(pContour); - eyeTrackingResult.cPupil = pRect.center; - eyeTrackingResult.pDiam = (pRect.boundingRect().height + pRect.boundingRect().width) / 2; + cPupil = pRect.center; + pDiam = (pRect.boundingRect().height + pRect.boundingRect().width) / 2; } @@ -88,12 +85,10 @@ void TrackerWorker::onFrameGrabbed(Mat src) if(cContour.size()>4){ /*Determine centroid with boundingRect*/ Rect cRect = boundingRect(cContour); - eyeTrackingResult.cCornea.x = cRect.x + (cRect.width / 2); - eyeTrackingResult.cCornea.y = cRect.y + (cRect.height / 2); + cCornea.x = cRect.x + (cRect.width / 2); + cCornea.y = cRect.y + (cRect.height / 2); } - emit(trackingResult(eyeTrackingResult)); - /*Generate preview image*/ Mat previewIm(src.size(), CV_8U, double(0)); previewIm(Rect(rois.at(0).x(),rois.at(0).y(), rois.at(0).width(), rois.at(0).height())) = pMask*255; @@ -108,8 +103,8 @@ void TrackerWorker::onFrameGrabbed(Mat src) outputIm = src; } - circle(outputIm, eyeTrackingResult.cPupil, 10, Scalar(0,255,0), -1, 8, 0); - circle(outputIm, eyeTrackingResult.cCornea, 10, Scalar(255,0,255), -1, 8, 0); + circle(outputIm, cPupil, 10, Scalar(0,255,0), -1, 8, 0); + circle(outputIm, cCornea, 10, Scalar(255,0,255), -1, 8, 0); //std::vector > pContourV = std::vector >(1, pContour); //drawContours(outputIm, pContourV, -1, Scalar(0,255,0), 2, 8); @@ -119,8 +114,14 @@ void TrackerWorker::onFrameGrabbed(Mat src) ellipse(outputIm, pRect, Scalar(0,255,0), 10, 8); + std::vector result; + result.push_back(cPupil.x); + result.push_back(cPupil.y); + result.push_back(cCornea.x); + result.push_back(cCornea.y); + result.push_back(pDiam); + emit(trackingResult(result)); emit(trackingPreview(outputIm)); - emit(trackingResult(eyeTrackingResult)); } void TrackerWorker::onThresholdChanged(int index, int value) diff --git a/TrackerWorker.h b/TrackerWorker.h index 8a0c36f..7cd4bc7 100644 --- a/TrackerWorker.h +++ b/TrackerWorker.h @@ -1,7 +1,5 @@ #ifndef TRACKERWORKER_H #define TRACKERWORKER_H -#include "TrackerWorkerInterface.h" - #include #include #include @@ -10,8 +8,7 @@ #include #include #include - -#include "TrackingResults.h" +#include "TrackerWorkerInterface.h" using namespace cv; @@ -38,10 +35,9 @@ public slots: signals: - //void trackingResult(QVector); - void trackingResult(TrackingResults eyeTrackingResults); void trackingPreview(Mat); void trackingRois(QVector); + void trackingResult(std::vector data); }; diff --git a/TrackingResults.h b/TrackingResults.h deleted file mode 100644 index 621ddff..0000000 --- a/TrackingResults.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef TRACKINGRESULTS_H -#define TRACKINGRESULTS_H -#include - - -struct TrackingResults{ - cv::Point cPupil; - cv::Point cCornea; - double pDiam; -}; - - - -#endif // TRACKINGRESULTS_H