/// <summary>
/// 特征点提取
/// </summary>
/// <param name="image_names">输入的图像路径</param>
/// <param name="key_points_for_all">生成的特征点集</param>
/// <param name="descriptor_for_all">生成的特征点描述符</param>
/// <param name="colors_for_all"></param>
private void ExtractFeatures(List<string> image_names, List<KeyPoint[]> key_points_for_all, List<Mat> descriptor_for_all, List<Vec3b[]> colors_for_all)
{
key_points_for_all.Clear();
descriptor_for_all.Clear();
Mat image;
//读取图像,获取图像特征点,并保存
var MySurf = OpenCvSharp.XFeatures2D.SURF.Create(800, 4, 3, true, true);
for (int it = 0; it <= image_names.Count - 1; ++it)
{
image = Cv2.ImRead(image_names[it]);
if (image.Empty()) continue;
Mat descriptor = new Mat();
Mat mask = new Mat();
KeyPoint[] key_points;
//偶尔出现内存分配失败的错误
MySurf.DetectAndCompute(image, mask, out key_points, descriptor);
//特征点过少,则排除该图像
if (key_points.Length <= 10) continue;
key_points_for_all.Add(key_points);
descriptor_for_all.Add(descriptor);
Vec3b[] colors = new Vec3b[key_points.Length];
for (int i = 0; i < key_points.Length - 1; ++i)
{
Point2f p = key_points[i].Pt;
colors[i] = image.At<Vec3b>((int)p.Y, (int)p.X);
}
colors_for_all.Add(colors);
}
}
OpenCvSharp特征点SURF提取
最新推荐文章于 2024-09-24 03:00:00 发布