00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <iostream>
00030 #include <cstdlib>
00031 #include <cstring>
00032
00033 #include "camera_caffe_main.h"
00034
00035 #define CHECK_OPTION_VALUE(argp) \
00036 if(!*argp || (*argp)[0] == '-') \
00037 { \
00038 cerr << "Error: value not specified for option " << arg << endl; \
00039 goto error; \
00040 }
00041
00042 #define CSV_PARSE_CHECK_ERROR(condition, str) \
00043 if (condition) \
00044 { \
00045 cerr << "Error: " << str << endl; \
00046 goto error; \
00047 }
00048
00049
00050
00051 using namespace std;
00052
00053 static void print_help(const char *app_name)
00054 {
00055 cerr << "Usage:" << app_name << " [options]\n\n";
00056 cerr << "OPTIONS:\n";
00057 cerr << "\t-h,--help\n\n";
00058
00059 cerr << "\t-width width camera width, <1 -- 4096>\n";
00060 cerr << "\t-height height camera height, <1 -- 4096>\n\n";
00061
00062 cerr << "\t-lib library image processing library\n\n";
00063
00064 cerr << "\t-model model_file CAFFE model file\n";
00065 cerr << "\t-trained trained_file CAFFE trained file\n";
00066 cerr << "\t-mean mean_file CAFFE mean file\n";
00067 cerr << "\t-label label_file CAFFE label file\n";
00068
00069 return;
00070 }
00071
00072 int parse_csv_args(camera_caffe_context *ctx, int argc, const char *argv[])
00073 {
00074 char **argp = (char **) argv;
00075 char *arg = (char *) argv[0];
00076
00077 if (argc == 1 || (arg && (!strcmp(arg, "-h") || !strcmp(arg, "--help"))))
00078 {
00079 print_help(argv[0]);
00080 exit(EXIT_SUCCESS);
00081 }
00082
00083 while ((arg = *(++argp)) != NULL)
00084 {
00085 if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
00086 {
00087 print_help(argv[0]);
00088 exit(EXIT_SUCCESS);
00089 }
00090 else if (!strcmp(arg, "-width"))
00091 {
00092 arg = *(++argp);
00093 ctx->width = atoi(arg);
00094 }
00095 else if (!strcmp(arg, "-height"))
00096 {
00097 arg = *(++argp);
00098 ctx->height = atoi(arg);
00099 }
00100 else if (!strcmp(arg, "-lib"))
00101 {
00102 arg = *(++argp);
00103 ctx->lib_file = strdup(arg);
00104 }
00105 else if (!strcmp(arg, "-model"))
00106 {
00107 arg = *(++argp);
00108 ctx->model_file = strdup(arg);
00109 }
00110 else if (!strcmp(arg, "-trained"))
00111 {
00112 arg = *(++argp);
00113 ctx->trained_file = strdup(arg);
00114 }
00115 else if (!strcmp(arg, "-mean"))
00116 {
00117 arg = *(++argp);
00118 ctx->mean_file = strdup(arg);
00119 }
00120 else if (!strcmp(arg, "-label"))
00121 {
00122 arg = *(++argp);
00123 ctx->label_file = strdup(arg);
00124 }
00125 else
00126 {
00127 CSV_PARSE_CHECK_ERROR(1, "Unknown option " << arg);
00128 }
00129 }
00130
00131
00132 CSV_PARSE_CHECK_ERROR(((ctx->width <= 0) || (ctx->width >= 4096))
00133 , "Input width should be among 0-4096");
00134 CSV_PARSE_CHECK_ERROR(((ctx->height <= 0) || (ctx->height > 4096))
00135 , "Input height should be among 0-4096");
00136 CSV_PARSE_CHECK_ERROR(!ctx->lib_file, "lib file missing!\n");
00137 CSV_PARSE_CHECK_ERROR(!ctx->model_file, "CAFFE modle file missing!\n");
00138 CSV_PARSE_CHECK_ERROR(!ctx->trained_file, "CAFFE trained file missing!\n");
00139 CSV_PARSE_CHECK_ERROR(!ctx->mean_file, "CAFFE mean file missing!\n");
00140 CSV_PARSE_CHECK_ERROR(!ctx->label_file, "CAFFE label file missing!\n");
00141 return 0;
00142
00143 error:
00144 print_help(argv[0]);
00145 return -1;
00146
00147 }
00148