Пример #1
0
        public static void ParseSingleImage(string imagePath, string symbol, string outPath)
        {
            SURFDescriptor    descriptor = new SURFDescriptor();
            List <ImageIndex> imgIndexes = new List <ImageIndex>();

            Mat image = Cv2.ImRead(imagePath, ImreadModes.Unchanged);

            KeyPoint[] keypoints;
            var        features = descriptor.Describe(image, out keypoints);

            if ((features.Rows > 0) && (features.Cols > 0))
            {
                float[] featuresBytes = new float[features.Rows * features.Cols];
                features.GetArray(0, 0, featuresBytes);

                var imgIdx = new List <ImageIndex>();
                imgIdx.Add(new ImageIndex()
                {
                    Features = featuresBytes,
                    MType    = features.Type(),
                    Cols     = features.Cols,
                    Rows     = features.Rows,
                    Symbol   = symbol,
                    Rarity   = 0
                });

                SaveToDisk(imgIdx, outPath);
            }
        }
Пример #2
0
        private static ImageIndex fromImage(SURFDescriptor descriptor, bool noimages, string outPath, Crew crew, Mat image)
        {
            image = image.SubMat(0, image.Rows * 7 / 10, 0, image.Cols);

            if (!noimages)
            {
                Cv2.ImWrite(Path.Combine(outPath, "data", "traindata", $"feat_{crew.symbol}.png"), image);
            }

            KeyPoint[] keypoints;
            var        features = descriptor.Describe(image, out keypoints);

            if ((features.Rows > 0) && (features.Cols > 0))
            {
                float[] featuresBytes = new float[features.Rows * features.Cols];
                features.GetArray(out featuresBytes);

                return(new ImageIndex()
                {
                    Features = featuresBytes,
                    MType = features.Type(),
                    Cols = features.Cols,
                    Rows = features.Rows,
                    Symbol = crew.symbol,
                    Rarity = crew.max_rarity
                });
            }

            return(null);
        }
Пример #3
0
        public Searcher(string mainpath)
        {
            _descriptor        = new SURFDescriptor();
            _indexedDatset     = Trainer.LoadFromDisk(mainpath);
            _descriptorMatcher = InitMatcher();

            _starFull    = new Mat(Path.Combine(mainpath, "data", "starfull.png"));
            _closeButton = new Mat(Path.Combine(mainpath, "data", "closebutton.png"));
        }
Пример #4
0
        public static void ParseDataset(string datacorepath, string outPath, bool noimages, Action <string> progress)
        {
            var crewPath  = Path.Combine(datacorepath, "static", "structured", "crew.json");
            var assetPath = Path.Combine(datacorepath, "static", "media", "assets");

            Crew[]            allcrew    = JsonConvert.DeserializeObject <Crew[]>(File.ReadAllText(crewPath));
            SURFDescriptor    descriptor = new SURFDescriptor();
            List <ImageIndex> imgIndexes = new List <ImageIndex>();

            foreach (Crew crew in allcrew)
            {
                if (crew.max_rarity < 4)
                {
                    continue;
                }

                progress($"Parsing {crew.name}...");

                string fileName = Path.Combine(assetPath, crew.imageUrlFullBody);
                Mat    image    = Cv2.ImRead(fileName, ImreadModes.Unchanged);
                image = image.SubMat(0, image.Rows * 7 / 10, 0, image.Cols);

                if (!noimages)
                {
                    Cv2.ImWrite(Path.Combine(outPath, "data", "traindata", $"feat_{crew.symbol}.png"), image);
                }

                KeyPoint[] keypoints;
                var        features = descriptor.Describe(image, out keypoints);

                if ((features.Rows > 0) && (features.Cols > 0))
                {
                    float[] featuresBytes = new float[features.Rows * features.Cols];
                    features.GetArray(0, 0, featuresBytes);

                    imgIndexes.Add(new ImageIndex()
                    {
                        Features = featuresBytes,
                        MType    = features.Type(),
                        Cols     = features.Cols,
                        Rows     = features.Rows,
                        Symbol   = crew.symbol,
                        Rarity   = crew.max_rarity
                    });
                }
            }

            SaveToDisk(imgIndexes, outPath);
        }
Пример #5
0
        public static void ParseDataset(string datacorepath, string outPath, bool noimages, Action <string> progress)
        {
            var crewPath  = Path.Combine(datacorepath, "static", "structured", "crew.json");
            var assetPath = Path.Combine(datacorepath, "static", "media", "assets");

            Crew[]            allcrew    = JsonConvert.DeserializeObject <Crew[]>(File.ReadAllText(crewPath));
            SURFDescriptor    descriptor = new SURFDescriptor();
            List <ImageIndex> imgIndexes = new List <ImageIndex>();

            bool useWeb = true;

            foreach (Crew crew in allcrew)
            {
                if (crew.max_rarity < 4)
                {
                    continue;
                }

                progress($"Parsing {crew.name}...");

                Mat image;

                // parse from web instead (since assets are no longer committed to GitHub)
                if (useWeb)
                {
                    using (var client = new WebClient())
                    {
                        using (BinaryReader reader = new BinaryReader(client.OpenRead($"https://assets.datacore.app/{crew.imageUrlFullBody}")))
                        {
                            image = Cv2.ImDecode(ReadAllBytes(reader), ImreadModes.Unchanged);
                        }
                    }
                }
                else
                {
                    string fileName = Path.Combine(assetPath, crew.imageUrlFullBody);
                    image = Cv2.ImRead(fileName, ImreadModes.Unchanged);
                }

                ImageIndex imgIndex = fromImage(descriptor, noimages, outPath, crew, image);
                if (imgIndex != null)
                {
                    imgIndexes.Add(imgIndex);
                }
            }

            SaveToDisk(imgIndexes, outPath);
        }