Commit c0dae7d1 authored by pixhawk's avatar pixhawk

[landauf] added new list for letters and updated the pattern list (confidence...

[landauf] added new list for letters and updated the pattern list (confidence and count are updated)
parent 260c0ce4
...@@ -49,9 +49,11 @@ void PxQuadMAV::receiveMessage(LinkInterface* link, mavlink_message_t message) ...@@ -49,9 +49,11 @@ void PxQuadMAV::receiveMessage(LinkInterface* link, mavlink_message_t message)
b.resize(256); b.resize(256);
mavlink_msg_pattern_detected_get_file(&message, (int8_t*)b.data()); mavlink_msg_pattern_detected_get_file(&message, (int8_t*)b.data());
b.append('\0'); b.append('\0');
QString path = QString(b); QString name = QString(b);
emit detectionReceived(uasId, path, 0, 0, 0, 0, 0, 0, 0, 0, mavlink_msg_pattern_detected_get_confidence(&message), detected.detected); if (detected.type == 0)
emit letterDetected(uasId, path, detected.confidence, detected.detected); emit patternDetected(uasId, name, detected.confidence, detected.detected);
else if (detected.type == 1)
emit letterDetected(uasId, name, detected.confidence, detected.detected);
} }
break; break;
case MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT: case MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT:
......
...@@ -290,7 +290,7 @@ signals: ...@@ -290,7 +290,7 @@ signals:
void waypointReached(UASInterface* uas, int id); void waypointReached(UASInterface* uas, int id);
void autoModeChanged(bool autoMode); void autoModeChanged(bool autoMode);
void parameterChanged(int uas, int component, QString parameterName, float value); void parameterChanged(int uas, int component, QString parameterName, float value);
void detectionReceived(int uasId, QString patternPath, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double confidence, bool detected); void patternDetected(int uasId, QString patternPath, float confidence, bool detected);
void letterDetected(int uasId, QString letter, float confidence, bool detected); void letterDetected(int uasId, QString letter, float confidence, bool detected);
/** /**
* @brief The battery status has been updated * @brief The battery status has been updated
......
...@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project ...@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project
* @brief List of detected objects * @brief List of detected objects
* @author Benjamin Knecht <mavteam@student.ethz.ch> * @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Lorenz Meier <mavteam@student.ethz.ch> * @author Lorenz Meier <mavteam@student.ethz.ch>
* @author Fabian Landau <mavteam@student.ethz.ch>
* *
*/ */
...@@ -37,13 +38,15 @@ This file is part of the PIXHAWK project ...@@ -37,13 +38,15 @@ This file is part of the PIXHAWK project
#include "GAudioOutput.h" #include "GAudioOutput.h"
#include <QDebug> #include <QDebug>
#include <QMap>
#include "MG.h" #include "MG.h"
ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) : ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) :
QWidget(parent), QWidget(parent),
patternList(), patternList(),
patternCount(), letterList(),
letterTimer(),
uas(NULL), uas(NULL),
patternFolder(folder), patternFolder(folder),
separator(" "), separator(" "),
...@@ -51,6 +54,8 @@ ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) : ...@@ -51,6 +54,8 @@ ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) :
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setUAS(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setUAS(UASInterface*)));
letterTimer.start(1000);
connect(&letterTimer, SIGNAL(timeout()), this, SLOT(decreaseLetterTime()));
} }
ObjectDetectionView::~ObjectDetectionView() ObjectDetectionView::~ObjectDetectionView()
...@@ -74,91 +79,108 @@ void ObjectDetectionView::setUAS(UASInterface* uas) ...@@ -74,91 +79,108 @@ void ObjectDetectionView::setUAS(UASInterface* uas)
//if (this->uas == NULL && uas != NULL) //if (this->uas == NULL && uas != NULL)
//{ //{
this->uas = uas; this->uas = uas;
connect(uas, SIGNAL(detectionReceived(int, QString, int, int, int, int, int, int, int, int, double, bool)), this, SLOT(newDetection(int,QString,int,int,int,int,int,int,int,int,double,bool))); connect(uas, SIGNAL(patternDetected(int, QString, float, bool)), this, SLOT(newPattern(int, QString, float, bool)));
connect(uas, SIGNAL(letterDetected(int,QString,float,bool)), this, SLOT(newLetter(int,QString,float,bool))); connect(uas, SIGNAL(letterDetected(int, QString, float, bool)), this, SLOT(newLetter(int, QString, float, bool)));
//} //}
} }
void ObjectDetectionView::newLetter(int uasId, QString letter, float confidence, bool detected) void ObjectDetectionView::newPattern(int uasId, QString patternPath, float confidence, bool detected)
{ {
// Emit audio message on detection if (detected)
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected letter " + letter); {
m_ui->nameLabel->setText(letter); if (!patternList.contains(patternPath))
m_ui->imageLabel->setText(letter); {
} // Emit audio message on detection
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected pattern " + QString(patternPath.split("/").last()).split(".").first());
void ObjectDetectionView::newDetection(int uasId, QString patternPath, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double confidence, bool detected) patternList.insert(patternPath, Pattern(patternPath, confidence));
{ }
Q_UNUSED(x1); else
Q_UNUSED(y1); {
Q_UNUSED(x2); Pattern pattern = patternList.value(patternPath);
Q_UNUSED(y2); if (confidence > pattern.confidence)
Q_UNUSED(x3); pattern.confidence = confidence;
Q_UNUSED(y3); ++pattern.count;
Q_UNUSED(x4); patternList.insert(patternPath, pattern);
Q_UNUSED(y4); }
newDetection(uasId, patternPath, confidence, detected);
// set list items
QList<Pattern> templist;
foreach (Pattern pattern, patternList)
templist.push_back(pattern);
qSort(templist);
m_ui->listWidget->clear();
foreach (Pattern pattern, templist)
m_ui->listWidget->addItem(pattern.name + separator + "(" + QString::number(pattern.count) + ")" + separator + QString::number(pattern.confidence));
// load image
QString filePath = MG::DIR::getSupportFilesDirectory() + "/" + patternFolder + "/" + patternPath.split("/").last();
QPixmap image = QPixmap(filePath);
if (image.width() > image.height())
image = image.scaledToWidth(m_ui->imageLabel->width());
else
image = image.scaledToHeight(m_ui->imageLabel->height());
m_ui->imageLabel->setPixmap(image);
// set textlabel
QString patternName = patternPath.split("/").last(); // Remove preceding folder names
patternName = patternName.split(".").first(); // Remove file ending
m_ui->nameLabel->setText("Pattern: " + patternName);
}
} }
void ObjectDetectionView::newDetection(int uasId, QString patternPath, float confidence, bool detected) void ObjectDetectionView::newLetter(int uasId, QString letter, float confidence, bool detected)
{ {
Q_UNUSED(confidence);
if (detected) if (detected)
{ {
if (patternList.contains(patternPath)) if (!letterList.contains(letter))
{ {
//qDebug() << "REDETECTED"; // Emit audio message on detection
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected letter " + letter);
QList<QAction*> actions = m_ui->listWidget->actions();
// Find action and update it
foreach (QAction* act, actions)
{
qDebug() << "ACTION";
if (act->text().trimmed().split(separator).first() == patternPath)
{
int count = patternCount.value(patternPath);
patternCount.insert(patternPath, count);
act->setText(patternPath + separator + "(#" + QString::number(count) + ")" + separator + QString::number(confidence));
}
}
QString filePath = MG::DIR::getSupportFilesDirectory() + "/" + patternFolder + "/" + patternPath.split("/").last();
qDebug() << "Loading:" << filePath;
QPixmap image = QPixmap(filePath);
image = image.scaledToWidth(m_ui->imageLabel->width());
m_ui->imageLabel->setPixmap(image);
QString patternName = patternPath.split("//").last(); // Remove preceding folder names
patternName = patternName.split(".").first(); // Remove file ending
// Set name and label letterList.insert(letter, Pattern(letter, 0));
m_ui->nameLabel->setText(patternName);
} }
else else
{ {
// Emit audio message on detection Pattern pattern = letterList.value(letter);
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected pattern " + QString(patternPath.split("/").last()).split(".").first()); pattern.confidence = 0;
++pattern.count;
letterList.insert(letter, pattern);
}
patternList.insert(patternPath, confidence); updateLetterList();
patternCount.insert(patternPath, 1);
QString filePath = MG::DIR::getSupportFilesDirectory() + "/" + patternFolder + "/" + patternPath.split("/").last(); // display letter
m_ui->letterLabel->setText(letter);
qDebug() << "Loading:" << filePath; // set textlabel
QPixmap image = QPixmap(filePath); m_ui->nameLabel->setText("Letter: " + letter);
QIcon ico(image); }
QAction* act = new QAction(ico, patternPath + separator + "(#" + QString::number(1) + ")" + separator + QString::number(confidence), this); }
connect(act, SIGNAL(triggered()), this, SLOT(takeAction()));
//m_ui->listWidget->addAction(act);
m_ui->listWidget->addItem(patternPath + separator + "(#" + QString::number(1) + ")" + separator + QString::number(confidence));
//m_ui->listWidget->addItem(patternPath + " " + QString::number(confidence));
image = image.scaledToWidth(m_ui->imageLabel->width());
m_ui->imageLabel->setPixmap(image);
QString patternName = patternPath.split("//").last(); // Remove preceding folder names
patternName = patternName.split(".").first(); // Remove file ending
// Set name and label void ObjectDetectionView::decreaseLetterTime()
m_ui->nameLabel->setText(patternName); {
qDebug() << "IMAGE SET" << patternFolder + "/" + patternPath; foreach (Pattern pattern, letterList)
} {
pattern.confidence -= 1;
letterList.insert(pattern.name, pattern);
} }
updateLetterList();
}
void ObjectDetectionView::updateLetterList()
{
// set list items
QList<Pattern> templist;
foreach (Pattern pattern, letterList)
templist.push_back(pattern);
qSort(templist);
m_ui->letterListWidget->clear();
foreach (Pattern pattern, templist)
m_ui->letterListWidget->addItem(pattern.name + separator + "(" + QString::number(pattern.count) + ")" + separator + QString::number(pattern.confidence));
} }
void ObjectDetectionView::takeAction() void ObjectDetectionView::takeAction()
......
...@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project ...@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project
* @brief List of detected objects * @brief List of detected objects
* @author Benjamin Knecht <mavteam@student.ethz.ch> * @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Lorenz Meier <mavteam@student.ethz.ch> * @author Lorenz Meier <mavteam@student.ethz.ch>
* @author Fabian Landau <mavteam@student.ethz.ch>
* *
*/ */
...@@ -47,8 +48,21 @@ namespace Ui { ...@@ -47,8 +48,21 @@ namespace Ui {
class ObjectDetectionView : public QWidget { class ObjectDetectionView : public QWidget {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(ObjectDetectionView) Q_DISABLE_COPY(ObjectDetectionView)
public:
explicit ObjectDetectionView(QString folder="patterns", QWidget *parent = 0); struct Pattern
{
Pattern() : name(QString()), confidence(0.0f), count(0) {}
Pattern(QString name, float confidence) : name(name), confidence(confidence), count(1) {}
bool operator<(const Pattern& other) const { return this->confidence > other.confidence; } // this comparison is intentionally wrong to sort the QList from highest confidence to lowest
QString name;
float confidence;
unsigned int count;
};
public:
explicit ObjectDetectionView(QString folder="patterns", QWidget *parent = 0);
virtual ~ObjectDetectionView(); virtual ~ObjectDetectionView();
/** @brief Resize widget contents */ /** @brief Resize widget contents */
...@@ -58,17 +72,19 @@ public slots: ...@@ -58,17 +72,19 @@ public slots:
/** @brief Set the UAS this view is currently associated to */ /** @brief Set the UAS this view is currently associated to */
void setUAS(UASInterface* uas); void setUAS(UASInterface* uas);
/** @brief Report new detection */ /** @brief Report new detection */
void newDetection(int uasId, QString patternPath, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double confidence, bool detected); void newPattern(int uasId, QString patternPath, float confidence, bool detected);
void newLetter(int uasId, QString letter, float confidence, bool detected); void newLetter(int uasId, QString letter, float confidence, bool detected);
void newDetection(int uasId, QString patternPath, float confidence, bool detected); void decreaseLetterTime();
void updateLetterList();
/** @brief Accept an internal action, update name and preview image label */ /** @brief Accept an internal action, update name and preview image label */
void takeAction(); void takeAction();
protected: protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
QMap<QString, double> patternList; ///< The detected patterns QMap<QString, Pattern> patternList; ///< The detected patterns with their confidence and detection count
QMap<QString, unsigned int> patternCount; ///< Number of detections per pattern QMap<QString, Pattern> letterList; ///< The detected letters with their confidence and detection count
UASInterface* uas; ///< The monitored UAS QTimer letterTimer; ///< A timer to "forget" old letters
UASInterface* uas; ///< The monitored UAS
QString patternFolder; ///< The base folder where pattern images are stored in QString patternFolder; ///< The base folder where pattern images are stored in
const QString separator; const QString separator;
......
...@@ -7,17 +7,20 @@ ...@@ -7,17 +7,20 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>246</width> <width>246</width>
<height>396</height> <height>403</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout" columnstretch="10,10" columnminimumwidth="0,0">
<item row="0" column="0"> <item row="0" column="0" colspan="2">
<widget class="QListWidget" name="listWidget"/> <widget class="QListWidget" name="listWidget"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="2">
<widget class="QListWidget" name="letterListWidget"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="imageLabel"> <widget class="QLabel" name="imageLabel">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
...@@ -36,7 +39,39 @@ ...@@ -36,7 +39,39 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="1">
<widget class="QLabel" name="letterLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>10</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
<property name="sizeIncrement">
<size>
<width>2</width>
<height>2</height>
</size>
</property>
<property name="baseSize">
<size>
<width>10</width>
<height>10</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 72pt;
color: white;</string>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="nameLabel"> <widget class="QLabel" name="nameLabel">
<property name="text"> <property name="text">
<string>No objects recognized</string> <string>No objects recognized</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment