public static SimpleFeature CreateFromFile(String fileName) { String data = File.ReadAllText(fileName); SimpleFeatureDesc desc = JsonConvert.DeserializeObject <SimpleFeatureDesc>(data); SimpleFeature sf = new SimpleFeature(desc); return(sf); }
public SimpleFeature(SimpleFeatureDesc desc, SIFT featureDetector = null) { size = desc.size; cropRect = new Rectangle(desc.cropPoint, size); mask = new Mat(desc.size, DepthType.Cv8U, 1); features = desc.features; CvInvoke.Rectangle(mask, desc.rect, new MCvScalar(255, 255, 255), -1); CvInvoke.Circle(mask, desc.maskPoint, 23, new MCvScalar(0, 0, 0), -1); //SimpleFeature sf = new SimpleFeature(new Point(842, 646), size, mask); if (desc.colorFilter != null) { SetColorFilter(desc.colorFilter.lowerBound, desc.colorFilter.upperBound); } //featureDetector = new SIFT(0,2,0.02,20,0.4); if (featureDetector == null) { this.featureDetector = new SIFT(0, 3, 0.04, 10, 0.8); } Emgu.CV.Flann.LinearIndexParams ip = new Emgu.CV.Flann.LinearIndexParams(); Emgu.CV.Flann.SearchParams sp = new SearchParams(); matcher = new FlannBasedMatcher(ip, sp); }
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(); }