ImgHashBase.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 ImgHashBase
  9. /**
  10. * The base class for image hash algorithms
  11. */
  12. public class ImgHashBase : Algorithm
  13. {
  14. protected override void Dispose(bool disposing)
  15. {
  16. try
  17. {
  18. if (disposing)
  19. {
  20. }
  21. if (IsEnabledDispose)
  22. {
  23. if (nativeObj != IntPtr.Zero)
  24. img_1hash_ImgHashBase_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal ImgHashBase(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new ImgHashBase __fromPtr__(IntPtr addr) { return new ImgHashBase(addr); }
  36. //
  37. // C++: void cv::img_hash::ImgHashBase::compute(Mat inputArr, Mat& outputArr)
  38. //
  39. /**
  40. * Computes hash of the input image
  41. * param inputArr input image want to compute hash value
  42. * param outputArr hash of the image
  43. */
  44. public void compute(Mat inputArr, Mat outputArr)
  45. {
  46. ThrowIfDisposed();
  47. if (inputArr != null) inputArr.ThrowIfDisposed();
  48. if (outputArr != null) outputArr.ThrowIfDisposed();
  49. img_1hash_ImgHashBase_compute_10(nativeObj, inputArr.nativeObj, outputArr.nativeObj);
  50. }
  51. //
  52. // C++: double cv::img_hash::ImgHashBase::compare(Mat hashOne, Mat hashTwo)
  53. //
  54. /**
  55. * Compare the hash value between inOne and inTwo
  56. * param hashOne Hash value one
  57. * param hashTwo Hash value two
  58. * return value indicate similarity between inOne and inTwo, the meaning
  59. * of the value vary from algorithms to algorithms
  60. */
  61. public double compare(Mat hashOne, Mat hashTwo)
  62. {
  63. ThrowIfDisposed();
  64. if (hashOne != null) hashOne.ThrowIfDisposed();
  65. if (hashTwo != null) hashTwo.ThrowIfDisposed();
  66. return img_1hash_ImgHashBase_compare_10(nativeObj, hashOne.nativeObj, hashTwo.nativeObj);
  67. }
  68. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  69. const string LIBNAME = "__Internal";
  70. #else
  71. const string LIBNAME = "opencvforunity";
  72. #endif
  73. // C++: void cv::img_hash::ImgHashBase::compute(Mat inputArr, Mat& outputArr)
  74. [DllImport(LIBNAME)]
  75. private static extern void img_1hash_ImgHashBase_compute_10(IntPtr nativeObj, IntPtr inputArr_nativeObj, IntPtr outputArr_nativeObj);
  76. // C++: double cv::img_hash::ImgHashBase::compare(Mat hashOne, Mat hashTwo)
  77. [DllImport(LIBNAME)]
  78. private static extern double img_1hash_ImgHashBase_compare_10(IntPtr nativeObj, IntPtr hashOne_nativeObj, IntPtr hashTwo_nativeObj);
  79. // native support for java finalize()
  80. [DllImport(LIBNAME)]
  81. private static extern void img_1hash_ImgHashBase_delete(IntPtr nativeObj);
  82. }
  83. }