Browse files

using cv::CommandLineParser instead of ofxArgs

  • Loading branch information...
1 parent 325063f commit adfff294649236bcbe8d39beabe5887274a7874e @vinjn vinjn committed Sep 5, 2011
View
47 CamServer/source/AppConfig.cpp
@@ -1,5 +1,4 @@
#include "AppConfig.h"
-#include "ofxArgs.h"
#include <stdio.h>
using cv::FileStorage;
@@ -42,30 +41,38 @@ AppConfig::AppConfig():CLIENT("localhost")
bool using_debug_file = true;
-void AppConfig::parse_args(int argc, char** argv)
+std::string AppConfig::parse_args(int argc, char** argv)
{
- ofxArgs args(argc, argv);
- //if (args.contains("-a"))
- // fixed_back_mode = false;
- //else
- // fixed_back_mode = true;
-
- if (args.contains("-client"))
- CLIENT = args.getString("-client");
-
+ const char *keys =
+ {
+ "{delay||0|delay ms}"
+ "{client||localhost|specify the client ip}"
+ "{port||3333|specify the client port}"
+ "{log| |false|write log to file}"
+ "{minim ||false|minim windows mode}"
+ "{finger||false|enable finger track}"
+ "{hand||false|enable hand track}"
+ "{a|aut|false|auto background mode}"
+ "{1| |0 |the input source, could be camera_idx/picture}"
+ };
+
+ cv::CommandLineParser args(argc, (const char**)argv, keys);
+ args.printParams();
+
+ fixed_back_mode = !args.get<bool>("a");
+ CLIENT = args.get<std::string>("client");
#ifndef _DEBUG
- using_debug_file = args.contains("-log");
+ using_debug_file = args.get<bool>("log");
#endif
+ minim_window = args.get<bool>("minim");
+ delay_for_run = args.get<int>("delay");
+ finger_track = args.get<bool>("finger");
+ hand_track = args.get<bool>("hand");
+ PORT = args.get<int>("port");
- minim_window = args.contains("-minim");
-
- if (args.contains("-delay"))
- delay_for_run = args.getInt("-delay");
+ std::string input_src = args.get<std::string>("1");
- finger_track = args.contains("-finger");
- hand_track = args.contains("-hand");
- if (args.contains("-port"))
- PORT = args.getInt("-port");
+ return input_src;
}
bool AppConfig::load_from(char* filename)
View
4 CamServer/source/AppConfig.h
@@ -12,7 +12,9 @@
struct AppConfig
{
AppConfig();
- void parse_args(int argc, char** argv);
+
+ //return the input_source
+ std::string parse_args(int argc, char** argv);
bool load_from(char* filename);
bool save_to(char* filename);
View
5 CamServer/source/VideoApp.cpp
@@ -82,8 +82,6 @@ VideoApp::VideoApp()
bool VideoApp::init(int argc, char** argv)
{
- theConfig.parse_args(argc, argv);
-
if (theConfig.minim_window)
{
#ifdef WIN32
@@ -93,9 +91,6 @@ bool VideoApp::init(int argc, char** argv)
#endif
}
- if (argc > 2)
- argc = 2;//hack the _input.init
-
if (!input.init(argc,argv))
{
input_inited = true;
View
1 CamServer/source/VideoApp.h
@@ -92,6 +92,7 @@ struct VideoApp
void run();
+private:
void parse_args(int argc, char** argv);
void send_custom_msg();
void send_tuio_msg();
View
11 CamServer/source/main.cpp
@@ -1,5 +1,6 @@
#include "ofxThread.h"
#include "VideoApp.h"
+#include "AppConfig.h"
#define VERSION "0.6.1"
@@ -17,7 +18,7 @@ struct StartThread: public ofxThread
{
void threadedFunction()
{
- printf("CamServer %s vinjn.z@gmail.com.\n", VERSION);
+ printf("CamServer %s vinjn.z@gmail.com.\n\n", VERSION);
for (int b=0;b<8;b++)
{
if (theApp.input_inited)//if VideoInput is already initialized
@@ -40,7 +41,6 @@ struct ReadyThread: public ofxThread
}
};
-
void say_byebye()
{
printf("CamServer %s vinjn.z@gmail.com.\n", VERSION);
@@ -55,7 +55,12 @@ void say_byebye()
int main(int argc, char** argv )
{
- enableMemleakCheck();
+ enableMemleakCheck();
+
+ std::string input_src = theConfig.parse_args(argc, argv);
+ argc = 2;
+ argv[1] = (char*)input_src.c_str();
+
StartThread start_thread;
start_thread.startThread(false, false);
View
8 CamServer/workspace/VisualStudio2008/CamServer.vcproj
@@ -196,14 +196,6 @@
>
</File>
<File
- RelativePath="..\..\..\_common\ofxArgs.cpp"
- >
- </File>
- <File
- RelativePath="..\..\..\_common\ofxArgs.h"
- >
- </File>
- <File
RelativePath="..\..\..\_common\ofxThread.cpp"
>
</File>

0 comments on commit adfff29

Please sign in to comment.