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)
b.resize(256);
mavlink_msg_pattern_detected_get_file(&message, (int8_t*)b.data());
b.append('\0');
QString path = QString(b);
emit detectionReceived(uasId, path, 0, 0, 0, 0, 0, 0, 0, 0, mavlink_msg_pattern_detected_get_confidence(&message), detected.detected);
emit letterDetected(uasId, path, detected.confidence, detected.detected);
QString name = QString(b);
if (detected.type == 0)
emit patternDetected(uasId, name, detected.confidence, detected.detected);
else if (detected.type == 1)
emit letterDetected(uasId, name, detected.confidence, detected.detected);
}
break;
case MAVLINK_MSG_ID_WATCHDOG_HEARTBEAT:
......
......@@ -290,7 +290,7 @@ signals:
void waypointReached(UASInterface* uas, int id);
void autoModeChanged(bool autoMode);
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);
/**
* @brief The battery status has been updated
......
......@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project
* @brief List of detected objects
* @author Benjamin Knecht <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
#include "GAudioOutput.h"
#include <QDebug>
#include <QMap>
#include "MG.h"
ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) :
QWidget(parent),
patternList(),
patternCount(),
letterList(),
letterTimer(),
uas(NULL),
patternFolder(folder),
separator(" "),
......@@ -51,6 +54,8 @@ ObjectDetectionView::ObjectDetectionView(QString folder, QWidget *parent) :
{
m_ui->setupUi(this);
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setUAS(UASInterface*)));
letterTimer.start(1000);
connect(&letterTimer, SIGNAL(timeout()), this, SLOT(decreaseLetterTime()));
}
ObjectDetectionView::~ObjectDetectionView()
......@@ -74,91 +79,108 @@ void ObjectDetectionView::setUAS(UASInterface* uas)
//if (this->uas == NULL && uas != NULL)
//{
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(letterDetected(int,QString,float,bool)), this, SLOT(newLetter(int,QString,float,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)));
//}
}
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) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected letter " + letter);
m_ui->nameLabel->setText(letter);
m_ui->imageLabel->setText(letter);
}
if (detected)
{
if (!patternList.contains(patternPath))
{
// 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)
{
Q_UNUSED(x1);
Q_UNUSED(y1);
Q_UNUSED(x2);
Q_UNUSED(y2);
Q_UNUSED(x3);
Q_UNUSED(y3);
Q_UNUSED(x4);
Q_UNUSED(y4);
newDetection(uasId, patternPath, confidence, detected);
patternList.insert(patternPath, Pattern(patternPath, confidence));
}
else
{
Pattern pattern = patternList.value(patternPath);
if (confidence > pattern.confidence)
pattern.confidence = confidence;
++pattern.count;
patternList.insert(patternPath, pattern);
}
// 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 (patternList.contains(patternPath))
if (!letterList.contains(letter))
{
//qDebug() << "REDETECTED";
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
// Emit audio message on detection
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected letter " + letter);
// Set name and label
m_ui->nameLabel->setText(patternName);
letterList.insert(letter, Pattern(letter, 0));
}
else
{
// Emit audio message on detection
if (detected) GAudioOutput::instance()->say("System " + QString::number(uasId) + " detected pattern " + QString(patternPath.split("/").last()).split(".").first());
Pattern pattern = letterList.value(letter);
pattern.confidence = 0;
++pattern.count;
letterList.insert(letter, pattern);
}
patternList.insert(patternPath, confidence);
patternCount.insert(patternPath, 1);
updateLetterList();
QString filePath = MG::DIR::getSupportFilesDirectory() + "/" + patternFolder + "/" + patternPath.split("/").last();
// display letter
m_ui->letterLabel->setText(letter);
qDebug() << "Loading:" << filePath;
QPixmap image = QPixmap(filePath);
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 textlabel
m_ui->nameLabel->setText("Letter: " + letter);
}
}
// Set name and label
m_ui->nameLabel->setText(patternName);
qDebug() << "IMAGE SET" << patternFolder + "/" + patternPath;
}
void ObjectDetectionView::decreaseLetterTime()
{
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()
......
......@@ -26,6 +26,7 @@ This file is part of the PIXHAWK project
* @brief List of detected objects
* @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Lorenz Meier <mavteam@student.ethz.ch>
* @author Fabian Landau <mavteam@student.ethz.ch>
*
*/
......@@ -47,8 +48,21 @@ namespace Ui {
class ObjectDetectionView : public QWidget {
Q_OBJECT
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();
/** @brief Resize widget contents */
......@@ -58,17 +72,19 @@ public slots:
/** @brief Set the UAS this view is currently associated to */
void setUAS(UASInterface* uas);
/** @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 newDetection(int uasId, QString patternPath, float confidence, bool detected);
void decreaseLetterTime();
void updateLetterList();
/** @brief Accept an internal action, update name and preview image label */
void takeAction();
protected:
virtual void changeEvent(QEvent *e);
QMap<QString, double> patternList; ///< The detected patterns
QMap<QString, unsigned int> patternCount; ///< Number of detections per pattern
UASInterface* uas; ///< The monitored UAS
QMap<QString, Pattern> patternList; ///< The detected patterns with their confidence and detection count
QMap<QString, Pattern> letterList; ///< The detected letters with their confidence and detection count
QTimer letterTimer; ///< A timer to "forget" old letters
UASInterface* uas; ///< The monitored UAS
QString patternFolder; ///< The base folder where pattern images are stored in
const QString separator;
......
......@@ -7,17 +7,20 @@
<x>0</x>
<y>0</y>
<width>246</width>
<height>396</height>
<height>403</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout" columnstretch="10,10" columnminimumwidth="0,0">
<item row="0" column="0" colspan="2">
<widget class="QListWidget" name="listWidget"/>
</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">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
......@@ -36,7 +39,39 @@
</property>
</widget>
</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">
<property name="text">
<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