ShapeDistanceExtractor.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.ShapeModule
  8. {
  9. // C++: class ShapeDistanceExtractor
  10. //javadoc: ShapeDistanceExtractor
  11. public class ShapeDistanceExtractor : Algorithm
  12. {
  13. protected override void Dispose (bool disposing)
  14. {
  15. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  16. try {
  17. if (disposing) {
  18. }
  19. if (IsEnabledDispose) {
  20. if (nativeObj != IntPtr.Zero)
  21. shape_ShapeDistanceExtractor_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal ShapeDistanceExtractor (IntPtr addr) : base (addr) { }
  32. // internal usage only
  33. public static new ShapeDistanceExtractor __fromPtr__ (IntPtr addr) { return new ShapeDistanceExtractor (addr); }
  34. //
  35. // C++: float cv::ShapeDistanceExtractor::computeDistance(Mat contour1, Mat contour2)
  36. //
  37. //javadoc: ShapeDistanceExtractor::computeDistance(contour1, contour2)
  38. public float computeDistance (Mat contour1, Mat contour2)
  39. {
  40. ThrowIfDisposed ();
  41. if (contour1 != null) contour1.ThrowIfDisposed ();
  42. if (contour2 != null) contour2.ThrowIfDisposed ();
  43. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  44. float retVal = shape_ShapeDistanceExtractor_computeDistance_10(nativeObj, contour1.nativeObj, contour2.nativeObj);
  45. return retVal;
  46. #else
  47. return -1;
  48. #endif
  49. }
  50. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  51. const string LIBNAME = "__Internal";
  52. #else
  53. const string LIBNAME = "opencvforunity";
  54. #endif
  55. // C++: float cv::ShapeDistanceExtractor::computeDistance(Mat contour1, Mat contour2)
  56. [DllImport (LIBNAME)]
  57. private static extern float shape_ShapeDistanceExtractor_computeDistance_10 (IntPtr nativeObj, IntPtr contour1_nativeObj, IntPtr contour2_nativeObj);
  58. // native support for java finalize()
  59. [DllImport (LIBNAME)]
  60. private static extern void shape_ShapeDistanceExtractor_delete (IntPtr nativeObj);
  61. }
  62. }