コード例 #1
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);
        }
コード例 #2
0
ファイル: Trainer.cs プロジェクト: magelite/datacore-bot
        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);
            }
        }
コード例 #3
0
ファイル: Trainer.cs プロジェクト: magelite/datacore-bot
        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);
        }
コード例 #4
0
ファイル: Searcher.cs プロジェクト: magelite/datacore-bot
        private ImageIndex MatchCrew(Mat crew)
        {
            KeyPoint[] keypoints;
            Mat        crew3Features = new Mat();

            _descriptor.Describe(crew, out keypoints).ConvertTo(crew3Features, MatType.CV_32F);

            var goodMatches = _descriptorMatcher.Match(crew3Features);
            var indexBest   = goodMatches.GroupBy(x => (x.ImgIdx)).Select(
                g => new
            {
                Key   = g.Key,
                Value = g.Count()
            }).OrderByDescending(x => (x.Value)).First();

            var result = _indexedDatset.Where(x => x.index == indexBest.Key).FirstOrDefault();

            result.score = indexBest.Value;

            return(result);
        }