用 OpenCVSharp 4.5 跑一遍 OpenCV 官方教程。
原 OpenCV 官方教程链接:OpenCV: Feature Detection
核心函数:
using System;
using OpenCvSharp;
using OpenCvSharp.XFeatures2D;
namespace ConsoleApp1
{
class tutorial47 : ITutorial
{
public void Run()
{
Mat src = Cv2.ImRead(@"I:\csharp\images\box_in_scene.png", ImreadModes.Grayscale);
if (src.Empty())
{
Console.WriteLine( "Could not open or find the image!\n");
return;
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SURF detector = SURF.Create(minHessian);
KeyPoint[] keypoints = detector.Detect(src);
//-- Draw keypoints
Mat img_keypoints = new Mat();
Cv2.DrawKeypoints(src, keypoints, img_keypoints);
//-- Show detected (drawn) keypoints
Cv2.ImShow("SURF Keypoints", img_keypoints);
Cv2.WaitKey();
}
}
}