This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abde56f
Showing
8 changed files
with
1,060 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef NOTIFYINGQGRAPHICSRECTITEM_H | ||
#define NOTIFYINGQGRAPHICSRECTITEM_H | ||
|
||
#include <QGraphicsRectItem> | ||
|
||
class NotifyingQGraphicsRectItem : public QObject, public QGraphicsRectItem | ||
{ | ||
Q_OBJECT | ||
protected: | ||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { | ||
if (change == ItemPositionHasChanged){ | ||
emit itemMoved(); | ||
} | ||
return QGraphicsRectItem::itemChange(change, value); | ||
} | ||
signals: | ||
void itemMoved(); | ||
}; | ||
|
||
#endif // NOTIFYINGQGRAPHICSRECTITEM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
#include "TrackerPlugin_PupilDiam.h" | ||
|
||
TrackerPlugin_PupilDiam::TrackerPlugin_PupilDiam(QObject *parent) | ||
{ | ||
ui = new Ui::TrackerPlugin_PupilDiam; | ||
trackerWorker = new TrackerWorker(); | ||
ui->setupUi(this); | ||
|
||
pixmapItem = new QGraphicsPixmapItem(); | ||
|
||
plotPens.push_back(new QPen(Qt::green)); | ||
plotPens.push_back(new QPen(Qt::green)); | ||
plotPens.push_back(new QPen(Qt::magenta)); | ||
plotPens.push_back(new QPen(Qt::magenta)); | ||
plotPens.push_back(new QPen(QColor(127,127,255))); | ||
|
||
for(int i =0;i<plotPens.size();i++){ | ||
plotPens.at(i)->setWidth(2); | ||
} | ||
|
||
rectPens.push_back(new QPen(Qt::green)); | ||
rectPens.push_back(new QPen(Qt::magenta)); | ||
|
||
for(int i =0;i<rectPens.size();i++){ | ||
rectPens.at(i)->setWidth(5); | ||
} | ||
|
||
//uiPlots = new QVector<QwtPlot*>(); | ||
uiPlots.push_back(ui->qwtPlot_1); | ||
uiPlots.push_back(ui->qwtPlot_2); | ||
uiPlots.push_back(ui->qwtPlot_3); | ||
uiPlots.push_back(ui->qwtPlot_4); | ||
uiPlots.push_back(ui->qwtPlot_5); | ||
|
||
uiSliders.push_back(ui->Slider_1); | ||
uiSliders.push_back(ui->Slider_2); | ||
|
||
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); | ||
uiLineEdits.push_back(ui->lineEdit_CorneaMaxArea); | ||
|
||
/*Position signalmapper*/ | ||
signalMapperPosition = new QSignalMapper(this); | ||
|
||
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]"); | ||
|
||
|
||
/*Prepare rects*/ | ||
for(int i=0;i<2;i++){ | ||
rectItems.push_back(new NotifyingQGraphicsRectItem()); | ||
rectItems.at(i)->setRect(QRect(0,0,maxRectWidth,maxRectWidth)); | ||
rectItems.at(i)->setPen(*rectPens.at(i)); | ||
rectItems.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); | ||
rectItems.at(i)->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); | ||
/*Signalmapper position*/ | ||
connect(rectItems.at(i), SIGNAL(itemMoved()), signalMapperPosition, SLOT(map())); | ||
signalMapperPosition->setMapping(rectItems.at(i), i); | ||
} | ||
connect(signalMapperPosition, SIGNAL(mapped(int)), this, SLOT(onItemPositionChanged(int))); | ||
|
||
|
||
/*Prepare curves*/ | ||
for(int i=0;i<plotPens.size();i++){ | ||
curves.push_back(new QwtPlotCurve("Curve")); | ||
curves.at(i)->setPen(*plotPens.at(i)); | ||
curves.at(i)->setRenderHint( QwtPlotItem::RenderAntialiased ); | ||
rectData.push_back(new QwtPointSeriesData); | ||
rectSamples.push_back(new QVector<QPointF>); | ||
curves.at(i)->attach(uiPlots.at(i)); | ||
} | ||
|
||
/*Checkboxes signalmapper*/ | ||
signalMapperCheckBoxes = new QSignalMapper(this); | ||
/*Connect checkboxes and sliders*/ | ||
connect(ui->checkBox_1, SIGNAL(clicked()), signalMapperCheckBoxes, SLOT(map())); | ||
connect(ui->checkBox_2, SIGNAL(clicked()), signalMapperCheckBoxes, SLOT(map())); | ||
connect(ui->checkBox_3, SIGNAL(clicked()), signalMapperCheckBoxes, SLOT(map())); | ||
connect(ui->checkBox_4, SIGNAL(clicked()), signalMapperCheckBoxes, SLOT(map())); | ||
connect(ui->checkBox_5, SIGNAL(clicked()), signalMapperCheckBoxes, SLOT(map())); | ||
signalMapperCheckBoxes->setMapping(ui->checkBox_1, 0); | ||
signalMapperCheckBoxes->setMapping(ui->checkBox_2, 1); | ||
signalMapperCheckBoxes->setMapping(ui->checkBox_3, 2); | ||
signalMapperCheckBoxes->setMapping(ui->checkBox_4, 3); | ||
signalMapperCheckBoxes->setMapping(ui->checkBox_5, 4); | ||
connect(signalMapperCheckBoxes, SIGNAL(mapped(int)), this, SLOT(onCheckBoxClicked(int))); | ||
|
||
/*Sliders signalmapper*/ | ||
signalMapperSliders = new QSignalMapper(this); | ||
/*Connect checkboxes and sliders*/ | ||
connect(ui->Slider_1, SIGNAL(sliderMoved(double)), signalMapperSliders, SLOT(map())); | ||
connect(ui->Slider_2, SIGNAL(sliderMoved(double)), signalMapperSliders, SLOT(map())); | ||
signalMapperSliders->setMapping(ui->Slider_1, 0); | ||
signalMapperSliders->setMapping(ui->Slider_2, 1); | ||
connect(signalMapperSliders, SIGNAL(mapped(int)), this, SLOT(onThreshSliderMoved(int))); | ||
|
||
/*Sliders Size signalmapper*/ | ||
signalMapperSliders_Size = new QSignalMapper(this); | ||
/*Connect checkboxes and sliders*/ | ||
connect(ui->Slider_Size_1, SIGNAL(sliderMoved(double)), signalMapperSliders_Size, SLOT(map())); | ||
connect(ui->Slider_Size_2, SIGNAL(sliderMoved(double)), signalMapperSliders_Size, SLOT(map())); | ||
signalMapperSliders_Size->setMapping(ui->Slider_Size_1, 0); | ||
signalMapperSliders_Size->setMapping(ui->Slider_Size_2, 1); | ||
connect(signalMapperSliders_Size, SIGNAL(mapped(int)), this, SLOT(onSizeSliderMoved(int))); | ||
|
||
/*LineEdit signalmapper*/ | ||
/*The signalmapper is an overkill at this point but since we used them for everything else, we'll stick to them for now*/ | ||
signalMapperLineEdit = new QSignalMapper(this); | ||
connect(ui->lineEdit_PupilMinArea, SIGNAL(editingFinished()), signalMapperLineEdit, SLOT(map())); | ||
connect(ui->lineEdit_PupilMaxArea, SIGNAL(editingFinished()), signalMapperLineEdit, SLOT(map())); | ||
connect(ui->lineEdit_CorneaMinArea, SIGNAL(editingFinished()), signalMapperLineEdit, SLOT(map())); | ||
connect(ui->lineEdit_CorneaMaxArea, SIGNAL(editingFinished()), signalMapperLineEdit, SLOT(map())); | ||
signalMapperLineEdit->setMapping(ui->lineEdit_PupilMinArea, 0); | ||
signalMapperLineEdit->setMapping(ui->lineEdit_PupilMaxArea, 1); | ||
signalMapperLineEdit->setMapping(ui->lineEdit_CorneaMinArea, 2); | ||
signalMapperLineEdit->setMapping(ui->lineEdit_CorneaMaxArea, 3); | ||
connect(signalMapperLineEdit, SIGNAL(mapped(int)), this, SLOT(onAreaConstraintsEditingFinished(int))); | ||
|
||
QIntValidator *intValidator = new QIntValidator(0, 2147483647 ,this); | ||
ui->lineEdit->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))); | ||
connect(this, SIGNAL(posChanged(int, QPoint)), trackerWorker, SLOT(onPosChanged(int, QPoint))); | ||
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<float>)), this, SLOT(onTrackingResult(QVector<float>))); | ||
connect(trackerWorker, SIGNAL(trackingResult(TrackingResults)), this, SLOT(onTrackingResult(TrackingResults))); | ||
} | ||
|
||
QObject *TrackerPlugin_PupilDiam::worker() | ||
{ | ||
return trackerWorker; | ||
} | ||
|
||
void TrackerPlugin_PupilDiam::initializeUI(QLayout *layout, QGraphicsScene *cameraScene, QSize cameraResolution) | ||
{ | ||
this->cameraResolution = cameraResolution; | ||
layout->addWidget(this); | ||
this->cameraScene = cameraScene; | ||
|
||
for(int i=0;i<rectItems.size();i++){ | ||
this->cameraScene->addItem(rectItems.at(i)); | ||
|
||
emit(thresholdChanged(i, uiSliders.at(i)->value())); | ||
emit(sizeChanged(i, QSize(rectItems.at(i)->rect().width(), rectItems.at(i)->rect().height()))); | ||
emit(posChanged(i, QPoint(rectItems.at(i)->pos().rx(),rectItems.at(i)->pos().ry()))); | ||
} | ||
|
||
/*Resize rectangles according to the correct size*/ | ||
if(cameraResolution.width()>cameraResolution.height()){ | ||
this->maxRectWidth = cameraResolution.height()/2; | ||
}else{ | ||
this->maxRectWidth = cameraResolution.width()/2; | ||
} | ||
for(int i=0;i<rectItems.size();i++){ | ||
rectItems.at(i)->setRect(QRect(0,0,maxRectWidth,maxRectWidth)); | ||
} | ||
} | ||
|
||
|
||
|
||
void TrackerPlugin_PupilDiam::onTrackingResult(TrackingResults result) | ||
{ | ||
int nPlots = 5; | ||
|
||
/*window is full - stop */ | ||
if(frameCount>wndLength){ | ||
for(int i=0;i<nPlots;i++){ | ||
rectSamples.at(i)->pop_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++){ | ||
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) | ||
{ | ||
|
||
bool isVisible = !uiPlots.at(index)->isVisible(); | ||
|
||
switch ( index ){ | ||
case 0: | ||
rectItems.at(index)->setVisible(isVisible); | ||
uiSliders.at(index)->setVisible(isVisible); | ||
uiSliders_Size.at(index)->setVisible(isVisible); | ||
break; | ||
case 2: | ||
rectItems.at(1)->setVisible(isVisible); | ||
uiSliders.at(1)->setVisible(isVisible); | ||
uiSliders_Size.at(1)->setVisible(isVisible); | ||
break; | ||
} | ||
|
||
|
||
uiPlots.at(index)->setVisible(isVisible); | ||
|
||
|
||
|
||
} | ||
|
||
void TrackerPlugin_PupilDiam::onThreshSliderMoved(int index) | ||
{ | ||
float value = uiSliders.at(index)->value(); | ||
emit(thresholdChanged(index, value)); | ||
} | ||
|
||
void TrackerPlugin_PupilDiam::onSizeSliderMoved(int index) | ||
{ | ||
float value = uiSliders_Size.at(index)->value(); | ||
if((rectItems.at(index)->pos().x() + maxRectWidth*value < cameraScene->width()) & | ||
(rectItems.at(index)->pos().y() + maxRectWidth*value < cameraScene->height())) { | ||
|
||
rectItems.at(index)->setRect(QRect(0,0,maxRectWidth*value,maxRectWidth*value)); | ||
emit(sizeChanged(index, QSize(rectItems.at(index)->rect().width(),rectItems.at(index)->rect().height()))); | ||
} | ||
} | ||
|
||
void TrackerPlugin_PupilDiam::on_lineEdit_editingFinished() | ||
{ | ||
wndLength = ui->lineEdit->text().toDouble(); | ||
for(int i=0;i<rectSamples.size();i++){ | ||
rectSamples.at(i)->clear(); | ||
frameCount = 0; | ||
} | ||
} | ||
|
||
void TrackerPlugin_PupilDiam::onAreaConstraintsEditingFinished(int index) | ||
{ | ||
emit(areaContraintsChanged(index, uiLineEdits.at(index)->text().toInt())); | ||
} | ||
|
||
void TrackerPlugin_PupilDiam::onItemPositionChanged(int index) | ||
{ | ||
if(rectItems.at(index)->pos().x() < 0){ | ||
rectItems.at(index)->setX(0); | ||
} | ||
if(rectItems.at(index)->pos().y() < 0){ | ||
rectItems.at(index)->setY(0); | ||
} | ||
if ((rectItems.at(index)->pos().x() + rectItems.at(index)->rect().width()) >= cameraResolution.width()){ | ||
rectItems.at(index)->setX(cameraResolution.width()-rectItems.at(index)->rect().width()); | ||
} | ||
if ((rectItems.at(index)->pos().y() + rectItems.at(index)->rect().height()) >= cameraResolution.height()){ | ||
rectItems.at(index)->setY(cameraResolution.height()-rectItems.at(index)->rect().height()); | ||
} | ||
|
||
emit(posChanged(index, QPoint(rectItems.at(index)->pos().x(),rectItems.at(index)->pos().y()))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#ifndef PUPILDIAMTRACKER_H | ||
#define PUPILDIAMTRACKER_H | ||
|
||
#include "TrackerInterface.h" | ||
#include "TrackerWorker.h" | ||
#include "ui_TrackerPlugin_PupilDiam.h" | ||
#include <qwt_plot.h> | ||
#include <qwt_plot_curve.h> | ||
#include <qwt_series_data.h> | ||
#include <QGraphicsScene> | ||
#include <QGraphicsPixmapItem> | ||
#include <QDebug> | ||
#include <QSignalMapper> | ||
#include <qwt_slider.h> | ||
#include <NotifyingQGraphicsRectItem.h> | ||
#include <QPoint> | ||
#include <QSize> | ||
#include <opencv2/core/core.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc/imgproc.hpp> | ||
#include <opencv2/objdetect/objdetect.hpp> | ||
#include <QObject> | ||
#include <QDebug> | ||
|
||
|
||
namespace Ui { | ||
class TrackerPlugin_PupilDiam; | ||
} | ||
|
||
class TrackerPlugin_PupilDiam : public QWidget, public TrackerInterface | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "org.PylonRecorder.TrackerInterface") | ||
Q_INTERFACES(TrackerInterface) | ||
|
||
public: | ||
explicit TrackerPlugin_PupilDiam(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; | ||
QGraphicsPixmapItem* pixmapItem; | ||
QVector<NotifyingQGraphicsRectItem*> rectItems; | ||
QVector<QPen*> plotPens; | ||
QVector<QPen*> rectPens; | ||
|
||
QVector<QVector<QPointF>*> rectSamples; | ||
QVector<QwtPointSeriesData*> rectData; | ||
QVector<QwtPlotCurve*> curves; | ||
|
||
/*ui pointers for use with signalmapper*/ | ||
QVector<QwtPlot*> uiPlots; | ||
QVector<QwtSlider*> uiSliders; | ||
QVector<QwtSlider*> uiSliders_Size; | ||
QVector<QCheckBox*> uiCheckboxes; | ||
QVector<QLineEdit*> uiLineEdits; | ||
|
||
int maxRectWidth = 200; | ||
const int bitDepth = 8; | ||
|
||
int t = 0; | ||
int wndLength = 100; | ||
int frameCount = 0; | ||
|
||
QSignalMapper* signalMapperPosition; | ||
QSignalMapper* signalMapperCheckBoxes; | ||
QSignalMapper* signalMapperSliders; | ||
QSignalMapper* signalMapperSliders_Size; | ||
QSignalMapper* signalMapperLineEdit; | ||
|
||
private slots: | ||
void onTrackingResult(TrackingResults result); | ||
void onCheckBoxClicked(int); | ||
void onThreshSliderMoved(int); | ||
void onSizeSliderMoved(int); | ||
void on_lineEdit_editingFinished(); | ||
void onAreaConstraintsEditingFinished(int); | ||
void onItemPositionChanged(int); | ||
|
||
signals: | ||
void sizeChanged(int index, QSize size); | ||
void posChanged(int index, QPoint pos); | ||
void thresholdChanged(int index, int value); | ||
void areaContraintsChanged(int index, int value); | ||
|
||
}; | ||
|
||
#endif // PUPILDIAMTRACKER_H |
Oops, something went wrong.