From b4d04c9460f2ceb10f82cce8dc41571d16e3bd8a Mon Sep 17 00:00:00 2001 From: matlabbe Date: Wed, 21 May 2014 15:24:24 +0000 Subject: [PATCH] Added console mode to Find-Object (see "--help"): > Find-Object.exe -console -objs "Path objects" git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@278 620bd6b2-0a58-f614-fd9a-1bd335dccda9 --- app/main.cpp | 143 +++++++++++++++++++++++++++++++++++++--- console_app/main.cpp | 15 ++--- src/Camera.cpp | 13 ++-- src/MainWindow.cpp | 15 ++++- tcpClient/TcpClient.cpp | 7 +- 5 files changed, 168 insertions(+), 25 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index ccd4c2a3..6ab38d85 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,18 +1,145 @@ #include +#include +#include #include "MainWindow.h" +#include "Settings.h" + +#include + +void my_handler(int s){ + printf("Ctrl-C catch! Quitting application...\n"); + QApplication::closeAllWindows(); + QApplication::quit(); +} + +void showUsage() +{ + printf("\nUsage:\n" +#ifdef WIN32 + " Find-Object.exe [options]\n" +#else + " find_object [options]\n" +#endif + "Options:\n" + " -console Don't use the GUI (by default the camera will be\n" + " started automatically). Option -objs must also be\n" + " used with valid objects.\n" + " -objs \"path\" Directory of the objects to detect.\n" + " -config \"path\" Path to configuration file (default: %s).\n" + " -help or --help Show usage.\n", Settings::iniDefaultPath().toStdString().c_str()); + exit(-1); +} int main(int argc, char* argv[]) { - /* Create tasks */ QApplication app(argc, argv); - MainWindow mainWindow; - mainWindow.showNormal(); + // parse options + bool guiMode = true; + QString objectsPath = ""; + QString configPath = Settings::iniDefaultPath(); - // Now wait for application to finish - app.connect( &app, SIGNAL( lastWindowClosed() ), - &app, SLOT( quit() ) ); - app.exec();// MUST be called by the Main Thread + for(int i=1; istatusBar()->currentMessage().isEmpty(); if(updateStatusMessage) { @@ -966,7 +967,7 @@ void MainWindow::startProcessing() } else { - printf("ERROR: Camera initialization failed! (with device %d)", Settings::getCamera_1deviceId()); + printf("[ERROR] Camera initialization failed! (with device %d)\n", Settings::getCamera_1deviceId()); } } } @@ -1656,6 +1657,18 @@ void MainWindow::update(const cv::Mat & image) // Emit homographies if(objectsDetected.size()) { + if(objectsDetected.size() > 1) + { + printf("(%s) %d objects detected!\n", + QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str(), + (int)objectsDetected.size()); + } + else + { + printf("(%s) Object %d detected!\n", + QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str(), + (int)objectsDetected.begin().key()); + } emit objectsFound(objectsDetected); } ui_->label_objectsDetected->setNum(objectsDetected.size()); diff --git a/tcpClient/TcpClient.cpp b/tcpClient/TcpClient.cpp index dca0b4d4..81a4221e 100644 --- a/tcpClient/TcpClient.cpp +++ b/tcpClient/TcpClient.cpp @@ -10,6 +10,7 @@ #include #include #include +#include TcpClient::TcpClient(const QString & hostname, quint16 port, QObject *parent) : QTcpSocket(parent), @@ -65,7 +66,8 @@ void TcpClient::readData() QPointF qtBottomLeft = qtHomography.map(QPointF(0,objectHeight)); QPointF qtBottomRight = qtHomography.map(QPointF(objectWidth,objectHeight)); - printf("Object %d detected, Qt corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n", + printf("(%s) Object %d detected, Qt corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n", + QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str(), id, qtTopLeft.x(), qtTopLeft.y(), qtTopRight.x(), qtTopRight.y(), @@ -93,7 +95,8 @@ void TcpClient::readData() inPts.push_back(cv::Point2f(objectWidth,objectHeight)); cv::perspectiveTransform(inPts, outPts, cvHomography); - printf("Object %d detected, CV corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n", + printf("(%s) Object %d detected, CV corners at (%f,%f) (%f,%f) (%f,%f) (%f,%f)\n", + QTime::currentTime().toString("HH:mm:ss.zzz").toStdString().c_str(), id, outPts.at(0).x, outPts.at(0).y, outPts.at(1).x, outPts.at(1).y,