Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                printUsage();
                return;
            }

            Config config = new Config();
            Inputs inputs = new Inputs();

            foreach (var arg in args)
            {
                if ("--try_harder".Equals(arg))
                {
                    config.TryHarder = true;
                }
                else if ("--pure_barcode".Equals(arg))
                {
                    config.PureBarcode = true;
                }
                else if ("--products_only".Equals(arg))
                {
                    config.ProductsOnly = true;
                }
                else if ("--dump_results".Equals(arg))
                {
                    config.DumpResults = true;
                }
                else if ("--dump_black_point".Equals(arg))
                {
                    config.DumpBlackPoint = true;
                }
                else if ("--multi".Equals(arg))
                {
                    config.Multi = true;
                }
                else if ("--brief".Equals(arg))
                {
                    config.Brief = true;
                }
                else if ("--recursive".Equals(arg))
                {
                    config.Recursive = true;
                }
                else if (arg.StartsWith("--crop"))
                {
                    int[]    crop   = new int[4];
                    String[] tokens = arg.Substring(7).Split(',');
                    for (int i = 0; i < crop.Length; i++)
                    {
                        crop[i] = int.Parse(tokens[i]);
                    }
                    config.Crop = crop;
                }
                else if (arg.StartsWith("--threads") && arg.Length >= 10)
                {
                    int threadsCount = int.Parse(arg.Substring(10));
                    if (threadsCount > 1)
                    {
                        config.Threads = threadsCount;
                    }
                }
                else if (arg.StartsWith("-"))
                {
                    Console.Error.WriteLine("Unknown command line option " + arg);
                    printUsage();
                    return;
                }
            }

            config.Hints = buildHints(config);

            foreach (var arg in args)
            {
                if (!arg.StartsWith("--"))
                {
                    addArgumentToInputs(arg, config, inputs);
                }
            }

            var threads       = new Dictionary <Thread, DecodeThread>(Math.Min(config.Threads, inputs.getInputCount()));
            var decodeObjects = new List <DecodeThread>();

            for (int x = 0; x < config.Threads; x++)
            {
                var decodeThread = new DecodeThread(config, inputs);
                decodeObjects.Add(decodeThread);
                var thread = new Thread(decodeThread.run);
                threads.Add(thread, decodeThread);
                thread.Start();
            }

            int successful = 0;

            foreach (var thread in threads.Keys)
            {
                thread.Join();
                successful += threads[thread].getSuccessful();
            }

            var completeResult = String.Empty;

            foreach (var decodeObject in decodeObjects)
            {
                completeResult += decodeObject.ResultString;
                completeResult += Environment.NewLine;
            }
            System.Windows.Forms.Clipboard.SetText(completeResult);

            int total = inputs.getInputCount();

            if (total > 1)
            {
                Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                                      " successfully (" + (successful * 100 / total) + "%)\n");
            }
        }
Beispiel #2
0
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            printUsage();
            return;
         }

         Config config = new Config();
         Inputs inputs = new Inputs();

         foreach (var arg in args)
         {
            if ("--try_harder".Equals(arg))
            {
               config.TryHarder = true;
            }
            else if ("--pure_barcode".Equals(arg))
            {
               config.PureBarcode = true;
            }
            else if ("--products_only".Equals(arg))
            {
               config.ProductsOnly = true;
            }
            else if ("--dump_results".Equals(arg))
            {
               config.DumpResults = true;
            }
            else if ("--dump_black_point".Equals(arg))
            {
               config.DumpBlackPoint = true;
            }
            else if ("--multi".Equals(arg))
            {
               config.Multi = true;
            }
            else if ("--brief".Equals(arg))
            {
               config.Brief = true;
            }
            else if ("--recursive".Equals(arg))
            {
               config.Recursive = true;
            }
            else if ("--autorotate".Equals(arg))
            {
               config.AutoRotate = true;
            }
            else if (arg.StartsWith("--crop"))
            {
               int[] crop = new int[4];
               String[] tokens = arg.Substring(7).Split(',');
               for (int i = 0; i < crop.Length; i++)
               {
                  crop[i] = int.Parse(tokens[i]);
               }
               config.Crop = crop;
            }
            else if (arg.StartsWith("--threads") && arg.Length >= 10)
            {
               int threadsCount = int.Parse(arg.Substring(10));
               if (threadsCount > 1)
               {
                  config.Threads = threadsCount;
               }
            }
            else if ("--get_from_clipboard".Equals(arg))
            {
               config.BitmapFromClipboard = (Bitmap)Clipboard.GetImage();
               if (config.BitmapFromClipboard == null)
               {
                  Console.Error.WriteLine("There is no image in the clipboard.");
                  Environment.ExitCode = 1;
                  return;
               }
               // Dummy
               inputs.addInput(".");
            }
            else if (arg.StartsWith("-"))
            {
               Console.Error.WriteLine("Unknown command line option " + arg);
               printUsage();
               return;
            }
         }

         config.Hints = buildHints(config);

         foreach (var arg in args)
         {
            if (!arg.StartsWith("--"))
            {
               addArgumentToInputs(arg, config, inputs);
            }
         }

         var threads = new Dictionary<Thread, DecodeThread>(Math.Min(config.Threads, inputs.getInputCount()));
         var decodeObjects = new List<DecodeThread>();
         for (int x = 0; x < config.Threads; x++)
         {
            var decodeThread = new DecodeThread(config, inputs);
            decodeObjects.Add(decodeThread);
            var thread = new Thread(decodeThread.run);
            threads.Add(thread, decodeThread);
            thread.Start();
         }

         int successful = 0;
         foreach (var thread in threads.Keys)
         {
            thread.Join();
            successful += threads[thread].getSuccessful();
         }

         var completeResult = String.Empty;
         foreach (var decodeObject in decodeObjects)
         {
            completeResult += decodeObject.ResultString;
            completeResult += Environment.NewLine;
         }
         Clipboard.SetText(completeResult);

         int total = inputs.getInputCount();
         if (total > 1)
         {
            Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                " successfully (" + (successful * 100 / total) + "%)\n");
         }
      }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                printUsage();
                return;
            }

            Config config = new Config();
            Inputs inputs = new Inputs();

            config.AutoRotate = true;
            foreach (var arg in args)
            {
                if (arg.StartsWith("--crop"))
                {
                    int[]    crop   = new int[4];
                    String[] tokens = arg.Substring(7).Split(',');
                    for (int i = 0; i < crop.Length; i++)
                    {
                        crop[i] = int.Parse(tokens[i]);
                    }
                    config.Crop = crop;
                }
                else if (arg.StartsWith("--threads") && arg.Length >= 10)
                {
                    int threadsCount = int.Parse(arg.Substring(10));
                    if (threadsCount > 1)
                    {
                        config.Threads = threadsCount;
                    }
                }
                else if (arg.StartsWith("-"))
                {
                    Console.Error.WriteLine("Unknown command line option " + arg);
                    printUsage();
                    return;
                }
            }

            config.Hints = buildHints(config);

            foreach (var arg in args)
            {
                if (!arg.StartsWith("--"))
                {
                    addArgumentToInputs(arg, config, inputs);
                }
            }

            var threads       = new Dictionary <Thread, DecodeThread>(Math.Min(config.Threads, inputs.getInputCount()));
            var decodeObjects = new List <DecodeThread>();

            for (int x = 0; x < config.Threads; x++)
            {
                var decodeThread = new DecodeThread(config, inputs);
                decodeObjects.Add(decodeThread);
                var thread = new Thread(decodeThread.run);
                threads.Add(thread, decodeThread);
                thread.Start();
            }

            foreach (var thread in threads.Keys)
            {
                thread.Join();
                threads[thread].getSuccessful();
            }
        }
Beispiel #4
0
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            printUsage();
            return;
         }

         Config config = new Config();
         Inputs inputs = new Inputs();


         foreach (var arg in args)
         {
            if ("--try_harder".Equals(arg))
            {
               config.TryHarder = true;
            }
            else if ("--pure_barcode".Equals(arg))
            {
               config.PureBarcode = true;
            }
            else if ("--products_only".Equals(arg))
            {
               config.ProductsOnly = true;
            }
            else if ("--dump_results".Equals(arg))
            {
               config.DumpResults = true;
            }
            else if ("--dump_black_point".Equals(arg))
            {
               config.DumpBlackPoint = true;
            }
            else if ("--multi".Equals(arg))
            {
               config.Multi = true;
            }
            else if ("--brief".Equals(arg))
            {
               config.Brief = true;
            }
            else if ("--recursive".Equals(arg))
            {
               config.Recursive = true;
            }
            else if (arg.StartsWith("--crop"))
            {
               int[] crop = new int[4];
               String[] tokens = arg.Substring(7).Split(',');
               for (int i = 0; i < crop.Length; i++)
               {
                  crop[i] = int.Parse(tokens[i]);
               }
               config.Crop = crop;
            }
            else if (arg.StartsWith("--threads") && arg.Length >= 10)
            {
               int threadsCount = int.Parse(arg.Substring(10));
               if (threadsCount > 1)
               {
                  config.Threads = threadsCount;
               }
            }
            else if (arg.StartsWith("-"))
            {
               Console.Error.WriteLine("Unknown command line option " + arg);
               printUsage();
               return;
            }
         }

         config.Hints = buildHints(config);

         foreach (var arg in args)
         {
            if (!arg.StartsWith("--"))
            {
               addArgumentToInputs(arg, config, inputs);
            }
         }

         var threads = new Dictionary<Thread, DecodeThread>(config.Threads);
         for (int x = 0; x < config.Threads; x++)
         {
            var decodeThread = new DecodeThread(config, inputs);
            var thread = new Thread(decodeThread.run);
            threads.Add(thread, decodeThread);
            thread.Start();
         }

         int successful = 0;
         foreach (var thread in threads.Keys)
         {
            thread.Join();
            successful += threads[thread].getSuccessful();
         }
         int total = inputs.getInputCount();
         if (total > 1)
         {
            Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                " successfully (" + (successful * 100 / total) + "%)\n");
         }
      }