public void TestMatrixRgbPixel() { using (var window = new ImageWindow()) using (var src = new MatrixRgbPixel()) { const string imagePath = "images\\lenna.bmp"; var bmp = new System.Drawing.Bitmap(imagePath); src.SetBitmap(bmp); window.SetImage(src); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); using (var image = new MatrixRgbPixel(src)) { image.PyramidUp(); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.ResizeImage(image.Width / 2, image.Height / 2); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); } using (var image = new MatrixRgbPixel(640, 480)) { // Quadratic does not work. MatrixRgbPixel.ResizeImageWithResizeImageInterporateKind(src, image, ResizeImageInterporateKind.Bilinear); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); } } }
public void TestDnnMmodFaceDetection() { const string imagePath = "images\\lenna.bmp"; if (IntPtr.Size == 4) { return; } using (var window = new ImageWindow()) using (var image = new MatrixRgbPixel()) using (var detector = new DnnMmodFaceDetection("D:/Data/Dlib/mmod_human_face_detector.dat")) { var bmp = new System.Drawing.Bitmap(imagePath); image.SetBitmap(bmp); image.PyramidUp(); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); var rects = detector.DetectFaces(image); foreach (var rect in rects) { Console.WriteLine(rect); } } }
public void RawApiDnnMmodDetectionUsingMemoryInput() { const string imagePath = "images\\lenna.bmp"; if (IntPtr.Size == 4) { return; } var imageBytes = File.ReadAllBytes(imagePath); IntPtr detector = IntPtr.Zero; IntPtr dets = IntPtr.Zero; try { using (var window = new ImageWindow()) using (var image = new MatrixRgbPixel()) { Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 0 && image.Height == 0); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); NativeMethods.dlib_load_bmp_matrix_rgbpixel(image.DlibMatrixRgbPixel, imageBytes, new IntPtr(imageBytes.Length)); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.SetBitmap(new System.Drawing.Bitmap(imagePath)); Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.PyramidUp(); Console.WriteLine($"Size: ({image.Width},{image.Height})"); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); dets = NativeMethods.vector_Rect_new1(); detector = NativeMethods.dlib_dnn_mmod_face_detection_construct("D:/Data/Dlib/mmod_human_face_detector.dat"); NativeMethods.dlib_dnn_mmod_face_detection_operator(detector, image.DlibMatrixRgbPixel, dets); long count = NativeMethods.vector_Rect_getSize(dets).ToInt64(); if (count > 0) { unsafe { Rect *rectangles = (Rect *)NativeMethods.vector_Rect_getPointer(dets).ToPointer(); for (int i = 0; i < count; i++) { Console.WriteLine(rectangles[i]); } } } } } finally { if (detector != IntPtr.Zero) { NativeMethods.dlib_dnn_mmod_face_detection_delete(detector); } if (dets != IntPtr.Zero) { NativeMethods.vector_Rect_delete(dets); } } }