/// <summary> /// Releases all resources used by this <see cref="NcnnObject"/>. /// </summary> /// <param name="disposing">Indicate value whether <see cref="IDisposable.Dispose"/> method was called.</param> private void Dispose(bool disposing) { if (this.IsDisposed) { return; } // pre-disposing { if (disposing) { // managed dispose } // unmanaged dispose } this.IsDisposed = true; if (disposing) { // managed dispose } // unmanaged dispose Ncnn.DestroyGpuInstance(); }
public void CheckClassification() { const string image = "goldfish.jpg"; using (var m = NcnnDotNet.OpenCV.Cv2.ImRead(image, NcnnDotNet.OpenCV.CvLoadImage.Color)) { if (m.IsEmpty) { Assert.False(true, $"Failed to load {image}."); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } var clsScores = new List <float>(); DetectSqueezeNet(m, clsScores); if (!clsScores.Any()) { Assert.False(true, $"Failed to classify {image}. Reason: No classification"); } if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } var top = PrintTop(clsScores); if (top.Item1 < 0.9) { Assert.False(true, $"Failed to classify {image}. Reason: Low Score"); } if (top.Item2 != 1) { Assert.False(true, $"Failed to classify {image}. Reason: Wrong class"); } } }
private static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine($"Usage: {nameof(PeleeNetSSDSeg)} [imagepath]"); return(-1); } var imagepath = args[0]; using (var m = Cv2.ImRead(imagepath, CvLoadImage.Grayscale)) { if (m.IsEmpty) { Console.WriteLine($"cv::imread {imagepath} failed"); return(-1); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } var objects = new List <Object>(); using var segOut = new NcnnDotNet.Mat(); DetectPeleeNet(m, objects, segOut); if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } DrawObjects(m, objects, segOut); } return(0); }
private static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine($"Usage: {nameof(ShuffleNetV2)} [imagepath]"); return(-1); } var imagepath = args[0]; using (var m = Cv2.ImRead(imagepath, CvLoadImage.Grayscale)) { if (m.IsEmpty) { Console.WriteLine($"cv::imread {imagepath} failed"); return(-1); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } var clsScores = new List <float>(); DetectShuffleNetV2(m, clsScores); if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } PrintTopK(clsScores, 3); } return(0); }
private static int Main(string[] args) { if (args.Length != 1) { Console.WriteLine($"Usage: {nameof(RetinaFace)} [imagepath]"); return(-1); } var imagepath = args[0]; using (var m = Cv2.ImRead(imagepath, CvLoadImage.Grayscale)) { if (m.IsEmpty) { Console.WriteLine($"cv::imread {imagepath} failed"); return(-1); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } var keyPoints = new List <FaceObject>(); DetectRetinaFace(m, keyPoints); if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } DrawFaceObject(m, keyPoints); } return(0); }
public DetectResult Detect(byte[] file) { using var frame = Cv2.ImDecode(file, CvLoadImage.Grayscale); if (frame.IsEmpty) { throw new NotSupportedException("This file is not supported!!"); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } using var inMat = Mat.FromPixels(frame.Data, NcnnDotNet.PixelType.Bgr2Rgb, frame.Cols, frame.Rows); var faceInfos = this._UltraFace.Detect(inMat).ToArray(); if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } return(new DetectResult(frame.Cols, frame.Rows, faceInfos)); }
public DetectResult Detect(byte[] file) { using var m = Cv2.ImDecode(file, CvLoadImage.Grayscale); if (m.IsEmpty) { throw new NotSupportedException("This file is not supported!!"); } if (Ncnn.IsSupportVulkan) { Ncnn.CreateGpuInstance(); } var objects = new List <Object>(); DetectYoloV3(m, objects); if (Ncnn.IsSupportVulkan) { Ncnn.DestroyGpuInstance(); } return(new DetectResult(m.Cols, m.Rows, objects)); }