我有一些方法和类,但是因为]]会引发错误。
'列表'不包含'GetEnumerator'的公共实例定义]
下面的第一种方法显示了正在使用的foreach:
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>>(); List features = GetFeatures(); AKAZE kaze = AKAZE.Create(); Mat desc = new Mat(); kaze.DetectAndCompute(img, null, out KeyPoint[] 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.OrderByDescending(x => (x.Value)).ToList()[0].Key : "Unknown"; }
下面的GetFeatures()
方法:
public static List GetFeatures()
{
SharpSerializer serializer = new SharpSerializer(true);
FileStream fs = File.Open(@"D:\NCBC\OpenCV\CustomCV\CustomCV\bin\Debug\features.bin", FileMode.Open);
object obj = serializer.Deserialize(fs);
List result = (List)obj;
fs.Flush();
fs.Close();
fs.Dispose();
return result;
}
以及已存储的信息
private static ExtractedFeature ExtractFeatures(string image)
{
Mat img = Cv2.ImRead(image);
string category = Path.GetFileNameWithoutExtension(image).Split('.')[0];
Console.WriteLine(category);
OpenCvSharp.AKAZE kaze = OpenCvSharp.AKAZE.Create();
Mat desc = new Mat();
kaze.DetectAndCompute(img, null, out KeyPoint[] keyPoints, desc);
ExtractedFeature result = new ExtractedFeature()
{
ImgData = desc.ToBytes(),
Cols = desc.Cols,
Rows = desc.Rows,
ImgType = desc.Type(),
Category = category
};
return result;
}
我有一些方法和类,但是由于'List'不包含'GetEnumerator'的公共实例定义而引发错误。下面的第一种方法显示了所使用的foreach:...
GetFeatures()返回List
而不是List<T>
您应该给List
一种类型,例如字符串或int
,它对应于列表包含的内容
您正在尝试将对象转换为类型List,但是只有在您的基础类型确实是列表或者其实现了List实现的所有接口的情况下,您才能执行此操作。