public static string Execute(string imagePath) { var img = Cv2.ImRead(imagePath); List <string> result = new List <string>(); List <KeyValuePair <string, double> > featureScores = new List <KeyValuePair <string, double> >(); var features = IndexImages.GetFeatures(); OpenCvSharp.AKAZE kaze = OpenCvSharp.AKAZE.Create(); KeyPoint[] keyPoints; Mat desc = new Mat(); kaze.DetectAndCompute(img, null, out keyPoints, desc); foreach (var feature in features) { var train = new Mat(feature.Rows, feature.Cols, feature.ImgType, feature.ImgData); var matches = GetMatches(desc, train); var score = GetScore(matches); if (score == double.MaxValue) { continue; } featureScores.Add(new KeyValuePair <string, double>(feature.Category, score)); } return(featureScores.Count > 0 ? featureScores.OrderBy(x => (x.Value)).ToList()[0].Key : "Unknown"); }
private static ExtractedFeature ExtractFeatures(string image) { Mat img = Cv2.ImRead(image); string category = Path.GetFileNameWithoutExtension(image).Split('.')[0]; OpenCvSharp.AKAZE kaze = OpenCvSharp.AKAZE.Create(); KeyPoint[] keyPoints; Mat desc = new Mat(); kaze.DetectAndCompute(img, null, out keyPoints, desc); ExtractedFeature result = new ExtractedFeature() { ImgData = desc.ToBytes(), Cols = desc.Cols, Rows = desc.Rows, ImgType = desc.Type(), Category = category }; return(result); }