PHash.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.Img_hashModule
  7. {
  8. // C++: class PHash
  9. /**
  10. * pHash
  11. *
  12. * Slower than average_hash, but tolerant of minor modifications
  13. *
  14. * This algorithm can combat more variation than averageHash, for more details please refer to CITE: lookslikeit
  15. */
  16. public class PHash : ImgHashBase
  17. {
  18. protected override void Dispose(bool disposing)
  19. {
  20. try
  21. {
  22. if (disposing)
  23. {
  24. }
  25. if (IsEnabledDispose)
  26. {
  27. if (nativeObj != IntPtr.Zero)
  28. img_1hash_PHash_delete(nativeObj);
  29. nativeObj = IntPtr.Zero;
  30. }
  31. }
  32. finally
  33. {
  34. base.Dispose(disposing);
  35. }
  36. }
  37. protected internal PHash(IntPtr addr) : base(addr) { }
  38. // internal usage only
  39. public static new PHash __fromPtr__(IntPtr addr) { return new PHash(addr); }
  40. //
  41. // C++: static Ptr_PHash cv::img_hash::PHash::create()
  42. //
  43. public static PHash create()
  44. {
  45. return PHash.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(img_1hash_PHash_create_10()));
  46. }
  47. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  48. const string LIBNAME = "__Internal";
  49. #else
  50. const string LIBNAME = "opencvforunity";
  51. #endif
  52. // C++: static Ptr_PHash cv::img_hash::PHash::create()
  53. [DllImport(LIBNAME)]
  54. private static extern IntPtr img_1hash_PHash_create_10();
  55. // native support for java finalize()
  56. [DllImport(LIBNAME)]
  57. private static extern void img_1hash_PHash_delete(IntPtr nativeObj);
  58. }
  59. }