1、在W10系统中使用.NET8,创建一个控制台项目。
2、NuGet添加,OpenCvSharp4、OpenCvSharp4.runtime.win,如下图。
3、 在控制台项目代码如下。
using System.Reflection.Metadata.Ecma335;
using OpenCvSharp;
using OpenCvSharp.Dnn;
using OpenCvSharp.Face;
using OpenCvSharp.Features2D;
using OpenCvSharp.XFeatures2D;
namespace OpenCVSharpDemo
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine($"OpenCV version:{Cv2.GetVersionString()}");
Console.ReadLine();
}
}
}
4、运行效果如下图。
5、如果为安装 OpenCvSharp4.runtime.win 可能遇到的问题。如下
System.TypeInitializationException:“The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.”
DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern' or one of its dependencies: 找不到指定的模块。 (0x8007007E)