示例#1
0
        public String[] GetFeatures(Bitmap bmp)
        {
            List <String> ret = new List <string>();

            foreach (SimpleFeature sf in features)
            {
                SimpleFeature.FeatureResult featureRet = sf.GetFeature(bmp);
                if (featureRet != null)
                {
                    ret.Add(featureRet.label);
                }
            }
            return(ret.ToArray());
        }
示例#2
0
        private void shoePointsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SimpleFeatureDesc autoSkillFeatureDesc = new SimpleFeatureDesc();

            autoSkillFeatureDesc.cropPoint = new Point(340, 150);
            autoSkillFeatureDesc.size      = new Size(600, 300);
            autoSkillFeatureDesc.rect      = new Rectangle(new Point(0, 0), autoSkillFeatureDesc.size);
            //autoSkillFeatureDesc.maskPoint = new Point(35, 37);
            autoSkillFeatureDesc.colorFilter = new SimpleFeatureColorFilter(new MCvScalar(16 - 10, 149 - 50, 106 - 50), new MCvScalar(16 + 50, 149 + 50, 106 + 50));
            autoSkillFeatureDesc.features.Add(new SimpleFeatureInfo(@"Linage2\SIFT\QuestA", "QuestA"));
            //autoSkillFeatureDesc.features.Add(new SimpleFeatureInfo(@"Linage2\SIFT\Quest2Doing", "Quest2Doing"));
            SimpleFeature sf = new SimpleFeature(autoSkillFeatureDesc);

            sf.Load(true);

            String json = JsonConvert.SerializeObject(autoSkillFeatureDesc, Formatting.Indented);

            autoSkillFeatureDesc = JsonConvert.DeserializeObject <SimpleFeatureDesc>(json);
            Console.WriteLine(json);

            //SimpleFeature sf = SimpleFeature.CreateFromFile(@"Linage2\SIFT\Quest2.json");
            //sf.Load(true);

            foreach (SimpleFeatureData sd in sf)
            {
                //Mat result = new Mat();
                //Mat result1 = new Mat();
                //Mat result2 = new Mat();
                //Mat result3 = new Mat();
                //Features2DToolbox.DrawKeypoints(sd.mat, sd.keyPoints, result, new Bgr(Color.Cyan));
                //lstMat.Add(result);

                /*Features2DToolbox.DrawKeypoints(sd.mat.Split()[0], sd.keyPoints, result1, new Bgr(Color.Blue));
                 * lstMat.Add(result1);
                 * Features2DToolbox.DrawKeypoints(sd.mat.Split()[1], sd.keyPoints, result2, new Bgr(Color.Green));
                 * lstMat.Add(result2);
                 * Features2DToolbox.DrawKeypoints(sd.mat.Split()[2], sd.keyPoints, result3, new Bgr(Color.Red));
                 * lstMat.Add(result3);*/
                //log(CVUtil.ToString(sd.keyPoints));
                //log(CVUtil.ToString(sd.descriptors));
                //Refresh();
                Mat mat = new Mat();
                CvInvoke.Resize(sd.mat, mat, new Size(300, 150));
                lstMat.Add(mat);
            }
            foreach (SimpleFeatureTestData sd in sf.testData)
            {
                Bitmap bmp = (Bitmap)Bitmap.FromFile(sd.filePath);
                SimpleFeature.FeatureResult featureRet = sf.GetFeature(bmp);
                if (featureRet != null)
                {
                    FileInfo fInto        = new FileInfo(sd.filePath);
                    String   correctLabel = fInto.Directory.Name;
                    Console.WriteLine(sd.filePath + " " + featureRet.label);
                    Mat testImage = sf.lastObserved.Clone();
                    if (correctLabel == featureRet.label)
                    {
                        CvInvoke.Polylines(testImage, featureRet.GetMatchBoundingPoint(), true, new MCvScalar(255, 0, 0), 2);
                    }
                    else
                    {
                        CvInvoke.Polylines(testImage, featureRet.GetMatchBoundingPoint(), true, new MCvScalar(255, 255, 255));
                    }
                    lstMat.Add(testImage);
                }
                else
                {
                    Console.WriteLine(sd.filePath + " NOT FOUND");
                    lstMat.Add(sf.lastObserved.Clone());
                }
                //break;
            }

            /*
             * String[] testPath = { @"Linage2\SIFT\Quest2NoQuest"};
             * foreach(String path in testPath)
             * {
             *  FileInfo[] files = Utils.GetFilesByExtensions(new DirectoryInfo(path), ".jpg", ".png").ToArray();
             *  foreach (FileInfo f in files)
             *  {
             *      Bitmap bmp = (Bitmap)Bitmap.FromFile(f.FullName);
             *      SimpleFeature.FeatureResult featureRet = sf.GetFeature(bmp);
             *      Mat mat = new Mat();
             *      if (featureRet != null)
             *      {
             *          mat = sf.lastObserved.Clone();
             *          CvInvoke.PutText(mat, featureRet.label, new Point(0, 20), FontFace.HersheyPlain, 1, new MCvScalar(255, 255, 255));
             *          Console.WriteLine(sf.MatchesToString(sf.lastMatches));
             *          lstMat.Add(mat);
             *      }
             *  }
             * }*/

            //ShowKeyPoints();
            Refresh();
        }