Fixed issue 19: Publish detected objects and position on TCP

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@243 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe
2014-05-05 23:08:01 +00:00
parent 6082ab4b63
commit fa07e735a6
14 changed files with 712 additions and 232 deletions
+34 -5
View File
@@ -12,6 +12,7 @@
#include "Settings.h"
#include "ParametersToolBox.h"
#include "AboutDialog.h"
#include "TcpServer.h"
#include "rtabmap/PdfPlot.h"
#include <iostream>
@@ -45,7 +46,8 @@ MainWindow::MainWindow(Camera * camera, const QString & settings, QWidget * pare
settings_(settings),
likelihoodCurve_(0),
lowestRefreshRate_(99),
objectsModified_(false)
objectsModified_(false),
tcpServer_(0)
{
ui_ = new Ui_mainWindow();
ui_->setupUi(this);
@@ -88,7 +90,7 @@ MainWindow::MainWindow(Camera * camera, const QString & settings, QWidget * pare
ui_->menuView->addAction(ui_->dockWidget_parameters->toggleViewAction());
ui_->menuView->addAction(ui_->dockWidget_objects->toggleViewAction());
ui_->menuView->addAction(ui_->dockWidget_plot->toggleViewAction());
connect(ui_->toolBox, SIGNAL(parametersChanged(const QStringList &)), this, SLOT(notifyParametersChanged(const QStringList &)));
connect(ui_->toolBox, SIGNAL(parametersChanged(const QStringList &)), this, SLOT(notifyParametersChanged(const QStringList &)));
ui_->imageView_source->setGraphicsViewMode(false);
ui_->imageView_source->setTextLabel(tr("Press \"space\" to start the camera..."));
@@ -152,6 +154,10 @@ connect(ui_->toolBox, SIGNAL(parametersChanged(const QStringList &)), this, SLOT
ui_->actionCamera_from_video_file->setChecked(!Settings::getCamera_5mediaPath().isEmpty() && !UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()));
ui_->actionCamera_from_directory_of_images->setChecked(!Settings::getCamera_5mediaPath().isEmpty() && UDirectory::exists(Settings::getCamera_5mediaPath().toStdString()));
ui_->label_ipAddress->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui_->label_port->setTextInteractionFlags(Qt::TextSelectableByMouse);
setupTCPServer();
if(Settings::getGeneral_autoStartCamera())
{
// Set 1 msec to see state on the status bar.
@@ -200,6 +206,21 @@ void MainWindow::closeEvent(QCloseEvent * event)
}
}
void MainWindow::setupTCPServer()
{
if(tcpServer_)
{
tcpServer_->close();
delete tcpServer_;
}
tcpServer_ = new TcpServer(Settings::getGeneral_port(), this);
connect(this, SIGNAL(objectsFound(QMultiMap<int,QPair<QRect,QTransform> >)), tcpServer_, SLOT(publishObjects(QMultiMap<int,QPair<QRect,QTransform> >)));
ui_->label_ipAddress->setText(tcpServer_->getHostAddress().toString());
ui_->label_port->setNum(tcpServer_->getPort());
printf("IP: %s\nport: %d\n",
tcpServer_->getHostAddress().toString().toStdString().c_str(), tcpServer_->getPort());
}
ParametersToolBox * MainWindow::parametersToolBox() const
{
return ui_->toolBox;
@@ -1007,10 +1028,11 @@ protected:
++outliers_;
}
}
if(Settings::getHomography_ignoreWhenAllInliers())
// ignore homography when all features are inliers
if(inliers_ == (int)outlierMask_.size() && !h_.empty())
{
// ignore homography when all features are inliers
if(inliers_ == (int)outlierMask_.size())
if(Settings::getHomography_ignoreWhenAllInliers() || cv::countNonZero(h_) < 1)
{
h_ = cv::Mat();
}
@@ -1506,6 +1528,13 @@ void MainWindow::notifyParametersChanged(const QStringList & paramChanged)
{
nearestNeighborParamsChanged = true;
}
if(iter->compare(Settings::kGeneral_port()) == 0 &&
Settings::getGeneral_port() != ui_->label_port->text().toInt() &&
Settings::getGeneral_port() != 0)
{
setupTCPServer();
}
}
if(Settings::getGeneral_autoUpdateObjects())
+3
View File
@@ -22,6 +22,7 @@ class Camera;
class ParametersToolBox;
class QLabel;
class AboutDialog;
class TcpServer;
namespace rtabmap
{
@@ -77,6 +78,7 @@ signals:
void objectsFound(const QMultiMap<int, QPair<QRect, QTransform> > &);
private:
void setupTCPServer();
void addObjectFromFile(const QString & filePath);
void showObject(ObjWidget * obj);
void updateData();
@@ -97,6 +99,7 @@ private:
int lowestRefreshRate_;
bool objectsModified_;
QMap<int, QByteArray> imagesMap_;
TcpServer * tcpServer_;
};
#endif /* MainWindow_H_ */
+13 -1
View File
@@ -423,7 +423,18 @@ void ParametersToolBox::changeParameter()
}
else if(spinBox)
{
Settings::setParameter(sender()->objectName(), spinBox->value());
if(spinBox->objectName().compare(Settings::kHomography_minimumInliers()) == 0 &&
spinBox->value() < 4)
{
Settings::setHomography_minimumInliers(4);
spinBox->blockSignals(true);
this->updateParameter(Settings::kHomography_minimumInliers());
spinBox->blockSignals(false);
}
else
{
Settings::setParameter(sender()->objectName(), spinBox->value());
}
}
else if(lineEdit)
{
@@ -545,6 +556,7 @@ void ParametersToolBox::changeParameter(const int & value)
{
Settings::setParameter(sender()->objectName(), value==Qt::Checked?true:false);
}
paramChanged.append(sender()->objectName());
emit parametersChanged(paramChanged);
}
+2 -1
View File
@@ -175,11 +175,12 @@ class Settings
PARAMETER(General, threads, int, 1, "Number of threads used for objects matching and homography computation. 0 means as many threads as objects. On InvertedSearch mode, multi-threading has only effect on homography computation.");
PARAMETER(General, multiDetection, bool, false, "Multiple detection of the same object.");
PARAMETER(General, multiDetectionRadius, int, 30, "Ignore detection of the same object in X pixels radius of the previous detections.");
PARAMETER(General, port, int, 0, "Port on objects detected are published. If port=0, a port is chosen automatically.")
PARAMETER(Homography, homographyComputed, bool, true, "Compute homography? On ROS, this is required to publish objects detected.");
PARAMETER(Homography, method, QString, "1:LMEDS;RANSAC", "Type of the robust estimation algorithm: least-median algorithm or RANSAC algorithm.");
PARAMETER(Homography, ransacReprojThr, double, 1.0, "Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). It usually makes sense to set this parameter somewhere in the range of 1 to 10.");
PARAMETER(Homography, minimumInliers, int, 10, "Minimum inliers to accept the homography.");
PARAMETER(Homography, minimumInliers, int, 10, "Minimum inliers to accept the homography. Value must be >= 4.");
PARAMETER(Homography, ignoreWhenAllInliers, bool, false, "Ignore homography when all features are inliers (sometimes when the homography doesn't converge, it returns the best homography with all features as inliers).");
public:
+99
View File
@@ -0,0 +1,99 @@
/*
* TCPServer.cpp
*
* Created on: 2014-05-05
* Author: mathieu
*/
#include "TcpServer.h"
#include <QtNetwork/QNetworkInterface>
#include <QtNetwork/QTcpSocket>
#include <QtGui/QTransform>
TcpServer::TcpServer(quint16 port, QObject * parent) :
QTcpServer(parent)
{
if (!this->listen(QHostAddress::Any, port))
{
printf("ERROR: Unable to start the TCP server: %s\n", this->errorString().toStdString().c_str());
return;
}
connect(this, SIGNAL(newConnection()), this, SLOT(addClient()));
}
QHostAddress TcpServer::getHostAddress() const
{
QHostAddress hostAddress;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
// use the first non-localhost IPv4 address
for (int i = 0; i < ipAddressesList.size(); ++i)
{
if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address())
{
hostAddress = ipAddressesList.at(i).toString();
break;
}
}
// if we did not find one, use IPv4 localhost
if (hostAddress.isNull())
{
hostAddress = QHostAddress(QHostAddress::LocalHost);
}
return hostAddress;
}
quint16 TcpServer::getPort() const
{
return this->serverPort();
}
void TcpServer::publishObjects(const QMultiMap<int, QPair<QRect, QTransform> > & objects)
{
if(objects.size())
{
QList<QTcpSocket*> clients = this->findChildren<QTcpSocket*>();
if(clients.size())
{
QVector<float> data(objects.size()*12);
int i=0;
for(QMultiMap<int, QPair<QRect, QTransform> >::const_iterator iter=objects.constBegin(); iter!=objects.constEnd(); ++iter)
{
data[i++] = iter.key();
data[i++] = iter.value().first.width();
data[i++] = iter.value().first.height();
data[i++] = iter.value().second.m11();
data[i++] = iter.value().second.m12();
data[i++] = iter.value().second.m13();
data[i++] = iter.value().second.m21();
data[i++] = iter.value().second.m22();
data[i++] = iter.value().second.m23();
data[i++] = iter.value().second.m31(); // dx
data[i++] = iter.value().second.m32(); // dy
data[i++] = iter.value().second.m33();
}
for(QList<QTcpSocket*>::iterator iter = clients.begin(); iter!=clients.end(); ++iter)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << data;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
(*iter)->write(block);
}
}
}
}
void TcpServer::addClient()
{
QTcpSocket * client = this->nextPendingConnection();
connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
}
+31
View File
@@ -0,0 +1,31 @@
/*
* TCPServer.h
*
* Created on: 2014-05-05
* Author: mathieu
*/
#ifndef TCPSERVER_H_
#define TCPSERVER_H_
#include <QtNetwork/QTcpServer>
class QNetworkSession;
class TcpServer : public QTcpServer
{
Q_OBJECT
public:
TcpServer(quint16 port = 0, QObject * parent = 0);
QHostAddress getHostAddress() const;
quint16 getPort() const;
private slots:
void addClient();
void publishObjects(const QMultiMap<int, QPair<QRect, QTransform> > & objects);
};
#endif /* TCPSERVER_H_ */
+37 -9
View File
@@ -287,13 +287,20 @@
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0">
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0,0">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="3" column="1">
<widget class="QLabel" name="label_timeIndexing">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_timeMatching">
<property name="text">
@@ -420,13 +427,6 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_timeIndexing">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
@@ -462,6 +462,34 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>IP address</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLabel" name="label_ipAddress">
<property name="text">
<string>0.0.0.0</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLabel" name="label_port">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -478,7 +506,7 @@
<x>0</x>
<y>0</y>
<width>360</width>
<height>120</height>
<height>86</height>
</rect>
</property>
<attribute name="label">