/// <summary> /// Dispose /// </summary> protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DpmInvoke.cveDPMDetectorRelease(ref _ptr, ref _sharedPtr); } }
/// <summary> /// create a new dpm detector with the specified files and classes /// </summary> /// <param name="files"></param> /// <param name="classes"></param> public DpmDetector(string[] files, string[] classes) { CvString[] cfiles = new CvString[files.Length]; for (int i = 0; i < files.Length; i++) { cfiles[i] = new CvString(files[i]); } CvString[] cclasses = new CvString[classes.Length]; for (int i = 0; i < classes.Length; i++) { cclasses[i] = new CvString(classes[i]); } try { using (var vfiles = new Util.VectorOfCvString(cfiles)) using (var vclasses = new Util.VectorOfCvString(cclasses)) _ptr = DpmInvoke.cveDPMDetectorCreate(vfiles, vclasses, ref _sharedPtr); } finally { foreach (var c in cfiles) { c.Dispose(); } foreach (var c in cclasses) { c.Dispose(); } } }
/// <summary> /// create a new dpm detector with the specified files and classes /// </summary> /// <param name="files"></param> /// <param name="classes"></param> /// <returns></returns> public static DpmDetector Create(string[] files, string[] classes) { CvString[] cfiles = new CvString[files.Length]; for (int i = 0; i < files.Length; i++) { cfiles[i] = new CvString(files[i]); } CvString[] cclasses = new CvString[classes.Length]; for (int i = 0; i < classes.Length; i++) { cclasses[i] = new CvString(classes[i]); } IntPtr dpm; using (var vfiles = new Util.VectorOfCvString(cfiles)) using (var vclasses = new Util.VectorOfCvString(cclasses)) dpm = DpmInvoke.cveDPMDetectorCreate(vfiles, vclasses); foreach (var c in cfiles) { c.Dispose(); } foreach (var c in cclasses) { c.Dispose(); } return(new DpmDetector(dpm)); }
/// <summary> /// Perform detection on the image /// </summary> /// <param name="mat">The image for detection.</param> /// <returns>The detection result</returns> public ObjectDetection[] Detect(Mat mat) { using (Util.VectorOfRect rects = new Util.VectorOfRect()) using (Util.VectorOfFloat scores = new Util.VectorOfFloat()) using (Util.VectorOfInt classIds = new Util.VectorOfInt()) { DpmInvoke.cveDPMDetectorDetect(_ptr, mat, rects, scores, classIds); ObjectDetection[] detections = new ObjectDetection[rects.Size]; for (var i = 0; i < detections.Length; i++) { detections[i] = new ObjectDetection(rects[i], scores[i], classIds[i]); } return(detections); } }