Exemplo n.º 1
0
        public override int Run(String[] remainingArguments)
        {
            ReferenceCardDatabase database = new ReferenceCardDatabase();
            using (Stream stream = File.OpenRead(DatabasePath))
            {
                database.Import(stream);
            }
            ReferenceCardRadialHashDetector detector = new ReferenceCardRadialHashDetector();
            using (Stream stream = File.OpenRead(DetectorPath))
            {
                detector.Import(stream);
            }

            double similarity;
            int cardID = detector.Detect(ImagePath, out similarity);
            if (cardID == -1)
            {
                Console.WriteLine("No card detected");
                return 1;
            }

            IReferenceCard card = database.Get(cardID);
            Console.WriteLine("Card detected: " + cardID + " - " + card.Name + ", similarity " + similarity);
            return 0;
        }
        public override int Run(String[] remainingArguments)
        {
            ReferenceCardDatabase database = new ReferenceCardDatabase();
            ReferenceCardRadialHashDetector detector = new ReferenceCardRadialHashDetector();

            using (StreamReader streamReader = File.OpenText(GathererDatabasePath))
            using (JsonTextReader reader = new JsonTextReader(streamReader))
            {
                JObject root = JToken.ReadFrom(reader) as JObject;
                JObject cards = root.GetValue("MTGCardInfo") as JObject;
                Dictionary<int, GathererCardData> cardDictionary = cards.ToObject<Dictionary<int, GathererCardData>>();
                foreach (KeyValuePair<int, GathererCardData> pair in cardDictionary)
                {
                    ReferenceCard card = new ReferenceCard
                    {
                        Name = pair.Value.name
                    };

                    database.Add(pair.Key, card);
                }
            }

            String[] paths = Directory.GetFiles(GathererImagesPath, "*.jpg", SearchOption.AllDirectories);
            foreach (String path in paths)
            {
                String imageIDStr = Path.GetFileNameWithoutExtension(path);
                int imageID;
                if (int.TryParse(imageIDStr, out imageID))
                {
                    detector.AddHash(imageID, path);
                }
            }

            using (Stream stream = File.OpenWrite(ExportDatabasePath))
            {
                database.Export(stream);
            }
            using (Stream stream = File.OpenWrite(ExportDetectorPath))
            {
                detector.Export(stream);
            }

            return 0;
        }