- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# samples/11_camera_object_identification/camera_caffe_csvparser.cpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
    00003  *
    00004  * Redistribution and use in source and binary forms, with or without
    00005  * modification, are permitted provided that the following conditions
    00006  * are met:
    00007  *  * Redistributions of source code must retain the above copyright
    00008  *    notice, this list of conditions and the following disclaimer.
    00009  *  * Redistributions in binary form must reproduce the above copyright
    00010  *    notice, this list of conditions and the following disclaimer in the
    00011  *    documentation and/or other materials provided with the distribution.
    00012  *  * Neither the name of NVIDIA CORPORATION nor the names of its
    00013  *    contributors may be used to endorse or promote products derived
    00014  *    from this software without specific prior written permission.
    00015  *
    00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    00017  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00019  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    00020  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00022  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00023  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    00024  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    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     /* check paramters */
    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