parse command line for rerate options; bump version to 0.6
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 26 Sep 2015 13:07:07 +0000 (15:07 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 26 Sep 2015 13:07:07 +0000 (15:07 +0200)
tools/rerate.c
version.h

index 28563e5..6c7ea9f 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <math.h>
 #include "../src/img.h"
 #include <opencv2/core/core_c.h>
@@ -288,6 +289,70 @@ cvShowImage( "Image2", image2);                   // Show our image inside it.
        return 0;
 }
 
+static void print_help(const char *app)
+{
+       printf("This tool will change frame rate using optical flow and interpolation.\n");
+       printf("Usage: %s [options] <input> <first> <output> <first> <oldfps> <newfps>\n", app);
+       printf(" -h --help            This help\n");
+       printf(" -d --depth <bits>    Change color depth from default %d to given bits\n", save_depth);
+       printf(" -b --border <pixles> Remove border pixles, if darker than image (try 1)\n");
+       printf(" -w --window <size>   Change optical flow window size (default %d)\n", flow_window);
+       printf(" -f --frames <number> Limit number of input frames (default infinite)\n");
+       printf(" input                Input image sequence (e.g. input_%%05d.ppm)\n");
+       printf(" output               Output image sequence (e.g. output_%%05d.ppm)\n");
+       printf(" first                Index of first input and output image\n");
+       printf(" oldfps               Old frame rate\n");
+       printf(" newfps               New frame rate\n");
+}
+
+static int handle_options(int argc, char **argv)
+{
+       int skip_args = 0;
+
+       while (1) {
+               int option_index = 0, c;
+               static struct option long_options[] = {
+                       {"help", 0, 0, 'h'},
+                       {"depth", 1, 0, 'd'},
+                       {"border", 1, 0, 'b'},
+                       {"window", 1, 0, 'w'},
+                       {"frames", 1, 0, 'f'},
+                       {0, 0, 0, 0},
+               };
+
+               c = getopt_long(argc, argv, "hd:b:w:f:", long_options, &option_index);
+
+               if (c == -1)
+                       break;
+
+               switch (c) {
+               case 'h':
+                       print_help(argv[0]);
+                       exit(0);
+               case 'd':
+                       save_depth = atoi(optarg);
+                       skip_args += 2;
+                       break;
+               case 'b':
+                       border = atoi(optarg);
+                       skip_args += 2;
+                       break;
+               case 'w':
+                       flow_window = atoi(optarg);
+                       skip_args += 2;
+                       break;
+               case 'f':
+                       limit_frames = atoi(optarg);
+                       skip_args += 2;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       return skip_args;
+}
+
 int main(int argc, char *argv[])
 {
        unsigned short *img1 = NULL, *img2 = NULL, *res = NULL;
@@ -295,55 +360,25 @@ int main(int argc, char *argv[])
        const char *inputname, *outputname;
        double oldfps, newfps, step, inputframe, baseframe, offset;
        int outputframe;
-       int _argc = argc - 1;
-       int _arg = 1;
+       int skip_args;
+       const char *app_name = argv[0];
        int rc;
 
-       if (_argc > 1 && !strcmp(argv[_arg], "--depth")) {
-               save_depth = atoi(argv[_arg+1]);
-               _arg += 2;
-               _argc -= 2;
-       }
-
-       if (_argc > 1 && !strcmp(argv[_arg], "--border")) {
-               border = atoi(argv[_arg+1]);
-               _arg += 2;
-               _argc -= 2;
-       }
-
-       if (_argc > 1 && !strcmp(argv[_arg], "--window")) {
-               flow_window = atoi(argv[_arg+1]);
-               _arg += 2;
-               _argc -= 2;
-       }
-
-       if (_argc > 1 && !strcmp(argv[_arg], "--frames")) {
-               limit_frames = atoi(argv[_arg+1]);
-               _arg += 2;
-               _argc -= 2;
-       }
+       skip_args = handle_options(argc, argv);
+       argc -= skip_args + 1;
+       argv += skip_args + 1;
 
-       if (_argc != 6) {
-               printf("This tool will change frame rate using optical flow and interpolation.\n");
-               printf("Usage: %s [--depth x] [--border x] [--window x] <input> <first> <output> <first> <oldfps> <newfps>\n", argv[0]);
-               printf(" --border <pixles> Remove border pixles, if darker than image (try 1)\n");
-               printf(" --depth <bits>    Change color depth from default %d to given bits\n", save_depth);
-               printf(" --window <size>   Change optical flow window size (default %d)\n", flow_window);
-               printf(" --frames <number> Limit number of input frames (default infinite)\n");
-               printf(" input             Input image sequence (e.g. input_%%05d.ppm)\n");
-               printf(" output            Output image sequence (e.g. output_%%05d.ppm)\n");
-               printf(" first             Index of first input and output image\n");
-               printf(" oldfps            Old frame rate\n");
-               printf(" newfps            New frame rate\n");
+       if (argc != 6) {
+               print_help(app_name);
                return 0;
        }
 
-       inputname = argv[_arg];
-       inputframe = atoi(argv[_arg+1]);
-       outputname = argv[_arg+2];
-       outputframe = atoi(argv[_arg+3]);
-       oldfps = strtod(argv[_arg+4], NULL);
-       newfps = strtod(argv[_arg+5], NULL);
+       inputname = argv[0];
+       inputframe = atoi(argv[1]);
+       outputname = argv[2];
+       outputframe = atoi(argv[3]);
+       oldfps = strtod(argv[4], NULL);
+       newfps = strtod(argv[5], NULL);
 
        step = oldfps / newfps;
        printf("Time Scale Factor: %.4f\n", step);
index 788ef18..3874c5d 100644 (file)
--- a/version.h
+++ b/version.h
@@ -1 +1 @@
-"0.5wip"
+"0.6"