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
This commit is contained in:
parent
17873bacfa
commit
b4d04c9460
145
app/main.cpp
145
app/main.cpp
@ -1,18 +1,145 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFile>
|
||||
#include "MainWindow.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
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
|
||||
|
||||
return 0;
|
||||
for(int i=1; i<argc; ++i)
|
||||
{
|
||||
if(strcmp(argv[i], "-objs") == 0)
|
||||
{
|
||||
++i;
|
||||
if(i < argc)
|
||||
{
|
||||
objectsPath = argv[i];
|
||||
if(objectsPath.contains('~'))
|
||||
{
|
||||
objectsPath.replace('~', QDir::homePath());
|
||||
}
|
||||
if(!QDir(objectsPath).exists())
|
||||
{
|
||||
printf("[ERROR] Path not valid : %s\n", objectsPath.toStdString().c_str());
|
||||
showUsage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showUsage();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(strcmp(argv[i], "-config") == 0)
|
||||
{
|
||||
++i;
|
||||
if(i < argc)
|
||||
{
|
||||
configPath = argv[i];
|
||||
if(configPath.contains('~'))
|
||||
{
|
||||
configPath.replace('~', QDir::homePath());
|
||||
}
|
||||
if(!QFile::exists(configPath))
|
||||
{
|
||||
printf("[ERROR] Configuration file doesn't exist : %s\n", configPath.toStdString().c_str());
|
||||
showUsage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showUsage();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(strcmp(argv[i], "-console") == 0)
|
||||
{
|
||||
guiMode = false;
|
||||
continue;
|
||||
}
|
||||
if(strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0)
|
||||
{
|
||||
showUsage();
|
||||
}
|
||||
|
||||
printf("[ERROR] Unrecognized option : %s\n", argv[i]);
|
||||
showUsage();
|
||||
}
|
||||
|
||||
printf("Options:\n");
|
||||
printf(" GUI mode = %s\n", guiMode?"true":false);
|
||||
printf(" Objects path: \"%s\"\n", objectsPath.toStdString().c_str());
|
||||
printf(" Settings path: \"%s\"\n", configPath.toStdString().c_str());
|
||||
|
||||
|
||||
MainWindow mainWindow(0, configPath);
|
||||
|
||||
int objectsLoaded = 0;
|
||||
if(!objectsPath.isEmpty())
|
||||
{
|
||||
objectsLoaded = mainWindow.loadObjects(objectsPath);
|
||||
if(!objectsLoaded)
|
||||
{
|
||||
printf("[WARNING] No objects loaded from \"%s\"\n", objectsPath.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if(objectsLoaded == 0 && !guiMode)
|
||||
{
|
||||
printf("[ERROR] In console mode, at least one object must be loaded! See -console option.\n");
|
||||
showUsage();
|
||||
}
|
||||
|
||||
if(guiMode)
|
||||
{
|
||||
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
|
||||
mainWindow.show();
|
||||
}
|
||||
else
|
||||
{
|
||||
mainWindow.startProcessing();
|
||||
}
|
||||
|
||||
|
||||
// Catch ctrl-c to close the gui
|
||||
struct sigaction sigIntHandler;
|
||||
sigIntHandler.sa_handler = my_handler;
|
||||
sigemptyset(&sigIntHandler.sa_mask);
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@ -13,11 +13,10 @@ void showUsage()
|
||||
{
|
||||
printf(
|
||||
"\n"
|
||||
"Return similarity between two images.\n"
|
||||
"Return similarity between two images (the number of similar features between the images).\n"
|
||||
"Usage :\n"
|
||||
" ./find_object-console [option] object.png scene.png\n"
|
||||
"Options: \n"
|
||||
" -total return total matches (default total)\n"
|
||||
" -inliers return inliers percentage : inliers / (inliers + outliers)\n"
|
||||
" -quiet don't show messages\n");
|
||||
|
||||
@ -39,15 +38,11 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
for(int i=1; i<argc-2; ++i)
|
||||
{
|
||||
if(std::string(argv[1]).compare("-total") == 0)
|
||||
{
|
||||
method = mTotal;
|
||||
}
|
||||
else if(std::string(argv[1]).compare("-inliers") == 0)
|
||||
if(std::string(argv[i]).compare("-inliers") == 0)
|
||||
{
|
||||
method = mInliers;
|
||||
}
|
||||
else if(std::string(argv[1]).compare("-quiet") == 0)
|
||||
else if(std::string(argv[i]).compare("-quiet") == 0)
|
||||
{
|
||||
quiet = true;
|
||||
}
|
||||
|
||||
@ -135,10 +135,10 @@ bool Camera::start()
|
||||
{
|
||||
images_.append(path.toStdString() + UDirectory::separator() + *iter);
|
||||
}
|
||||
printf("Loaded %d filenames.\n", (int)images_.size());
|
||||
printf("Camera: Reading %d images from directory \"%s\"...\n", (int)images_.size(), path.toStdString().c_str());
|
||||
if(images_.isEmpty())
|
||||
{
|
||||
printf("WARNING: Directory \"%s\" is empty (no images matching the \"%s\" extensions). "
|
||||
printf("[WARNING] Directory \"%s\" is empty (no images matching the \"%s\" extensions). "
|
||||
"If you want to disable loading automatically this directory, "
|
||||
"clear the Camera/mediaPath parameter. By default, webcam will be used instead of the directory.\n",
|
||||
path.toStdString().c_str(),
|
||||
@ -151,7 +151,11 @@ bool Camera::start()
|
||||
capture_.open(path.toStdString().c_str());
|
||||
if(!capture_.isOpened())
|
||||
{
|
||||
printf("WARNING: Cannot open file \"%s\". If you want to disable loading automatically this video file, clear the Camera/mediaPath parameter. By default, webcam will be used instead of the file.\n", path.toStdString().c_str());
|
||||
printf("[WARNING] Cannot open file \"%s\". If you want to disable loading automatically this video file, clear the Camera/mediaPath parameter. By default, webcam will be used instead of the file.\n", path.toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Camera: Reading from video file \"%s\"...\n", path.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
if(!capture_.isOpened() && images_.empty())
|
||||
@ -163,11 +167,12 @@ bool Camera::start()
|
||||
capture_.set(CV_CAP_PROP_FRAME_WIDTH, double(Settings::getCamera_2imageWidth()));
|
||||
capture_.set(CV_CAP_PROP_FRAME_HEIGHT, double(Settings::getCamera_3imageHeight()));
|
||||
}
|
||||
printf("Camera: Reading from camera device %d...\n", Settings::getCamera_1deviceId());
|
||||
}
|
||||
}
|
||||
if(!capture_.isOpened() && images_.empty())
|
||||
{
|
||||
printf("Failed to open a capture object!\n");
|
||||
printf("[ERROR] Failed to open a capture object!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -921,6 +921,7 @@ void MainWindow::updateData()
|
||||
|
||||
void MainWindow::startProcessing()
|
||||
{
|
||||
printf("Starting camera...\n");
|
||||
bool updateStatusMessage = this->statusBar()->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());
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <QtGui/QTransform>
|
||||
#include <QtCore/QPointF>
|
||||
#include <QtCore/QTime>
|
||||
|
||||
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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user