Added JSON optional output when in console mode (see --json option)

Added --scene option to process a single scene file
Moved some apps in tools subfolder


git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@362 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe
2014-08-01 21:11:26 +00:00
parent 43e855e822
commit 6a0136cc16
18 changed files with 482 additions and 56 deletions
+42
View File
@@ -0,0 +1,42 @@
### Qt Gui stuff ###
SET(headers_ui
ImagesTcpServer.h
)
#This will generate moc_* for Qt
QT4_WRAP_CPP(moc_srcs ${headers_ui})
### Qt Gui stuff end###
SET(SRC_FILES
ImagesTcpServer.cpp
main.cpp
${moc_srcs}
)
SET(INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}
${OpenCV_INCLUDE_DIRS}
)
INCLUDE(${QT_USE_FILE})
SET(LIBRARIES
${OpenCV_LIBS}
${QT_LIBRARIES}
)
# Make sure the compiler can find include files from our library.
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
# Add binary called "example" that is built from the source file "main.cpp".
# The extension is automatically found.
ADD_EXECUTABLE(tcpImagesServer ${SRC_FILES})
TARGET_LINK_LIBRARIES(tcpImagesServer find_object ${LIBRARIES})
SET_TARGET_PROPERTIES( tcpImagesServer
PROPERTIES OUTPUT_NAME ${PROJECT_PREFIX}-tcpImagesServer)
INSTALL(TARGETS tcpImagesServer
RUNTIME DESTINATION bin COMPONENT runtime
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime)
+93
View File
@@ -0,0 +1,93 @@
/*
* ImagesTcpServer.cpp
*
* Created on: 2014-05-21
* Author: mathieu
*/
#include "find_object/Settings.h"
#include "find_object/QtOpenCV.h"
#include "ImagesTcpServer.h"
#include <QtNetwork/QNetworkInterface>
#include <QtNetwork/QTcpSocket>
#include <QtGui/QTransform>
ImagesTcpServer::ImagesTcpServer(float hz, const QString & path, QObject * parent) :
QTcpServer(parent)
{
// Set camera parameters
Settings::setCamera_4imageRate(hz);
Settings::setCamera_5mediaPath(path);
connect(this, SIGNAL(newConnection()), this, SLOT(addClient()));
connect(&camera_, SIGNAL(imageReceived(const cv::Mat &)), this, SLOT(publishImage(const cv::Mat &)));
}
QHostAddress ImagesTcpServer::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 ImagesTcpServer::getPort() const
{
return this->serverPort();
}
void ImagesTcpServer::publishImage(const cv::Mat & image)
{
QList<QTcpSocket*> clients = this->findChildren<QTcpSocket*>();
if(clients.size())
{
std::vector<unsigned char> buf;
cv::imencode(".png", image, buf);
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 << (quint64)0;
out.writeRawData((char*)buf.data(), (int)buf.size());
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
(*iter)->write(block);
}
}
else
{
printf("Paused...\n");
camera_.pause();
}
}
void ImagesTcpServer::addClient()
{
QTcpSocket * client = this->nextPendingConnection();
connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
if(!camera_.isRunning())
{
printf("Start...\n");
camera_.start();
}
}
+33
View File
@@ -0,0 +1,33 @@
/*
* ImagesTcpServer.h
*
* Created on: 2014-05-21
* Author: mathieu
*/
#ifndef TCPCLIENT_H_
#define TCPCLIENT_H_
#include "find_object/Camera.h"
#include <QtNetwork/QTcpServer>
class ImagesTcpServer : public QTcpServer
{
Q_OBJECT
public:
ImagesTcpServer(float hz = 10.0f, const QString & path = "", QObject * parent = 0);
QHostAddress getHostAddress() const;
quint16 getPort() const;
private Q_SLOTS:
void addClient();
void publishImage(const cv::Mat & image);
private:
Camera camera_;
};
#endif /* TCPCLIENT_H_ */
+106
View File
@@ -0,0 +1,106 @@
/*
* main.cpp
*
* Created on: 2014-05-05
* Author: mathieu
*/
#include <QtNetwork/QNetworkInterface>
#include <QtCore/QCoreApplication>
#include "ImagesTcpServer.h"
void showUsage()
{
printf("imagesTcpServer [options]\n"
" Options:\n"
" -hz #.# Image rate (default 10 Hz).\n"
" -p # Set manually a port to which the clients will connect.\n"
" -path \"\" Set a path of a directory of images or a video file.\n");
exit(-1);
}
int main(int argc, char * argv[])
{
QString ipAddress;
float hz = 10.0f;
quint16 port = 0;
QString path;
for(int i=1; i<argc; ++i)
{
if(strcmp(argv[i], "-hz") == 0)
{
++i;
if(i < argc)
{
hz = std::atof(argv[i]);
if(hz < 0.0f)
{
printf("[ERROR] Image rate not valid : %s\n", argv[i]);
showUsage();
}
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "-p") == 0)
{
++i;
if(i < argc)
{
int v = std::atoi(argv[i]);
if(v < 0)
{
printf("[ERROR] Port not valid : %s\n", argv[i]);
showUsage();
}
port = v;
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "-path") == 0)
{
++i;
if(i < argc)
{
path = argv[i];
}
else
{
showUsage();
}
continue;
}
printf("Unrecognized option: %s\n", argv[i]);
showUsage();
}
if(!path.isEmpty())
{
printf("Using images from path \"%s\"\n", path.toStdString().c_str());
}
QCoreApplication app(argc, argv);
ImagesTcpServer server(hz, path);
if (!server.listen(QHostAddress::Any, port))
{
printf("ERROR: Unable to start the TCP server: %s\n", server.errorString().toStdString().c_str());
return -1;
}
printf("Images server waiting on \"%s:%d\"...\n",
server.getHostAddress().toString().toStdString().c_str(), server.getPort());
return app.exec();
}