ImgHashBase.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.Img_hashModule {
  8. // C++: class ImgHashBase
  9. //javadoc: ImgHashBase
  10. public class ImgHashBase : Algorithm {
  11. protected override void Dispose(bool disposing) {
  12. #if (UNITY_ANDROID && !UNITY_EDITOR)
  13. try {
  14. if (disposing) {
  15. }
  16. if (IsEnabledDispose) {
  17. if (nativeObj != IntPtr.Zero)
  18. img_1hash_ImgHashBase_delete(nativeObj);
  19. nativeObj = IntPtr.Zero;
  20. }
  21. } finally {
  22. base.Dispose(disposing);
  23. }
  24. #else
  25. return;
  26. #endif
  27. }
  28. protected internal ImgHashBase(IntPtr addr) : base(addr) { }
  29. // internal usage only
  30. public static new ImgHashBase __fromPtr__(IntPtr addr) { return new ImgHashBase(addr); }
  31. //
  32. // C++: double cv::img_hash::ImgHashBase::compare(Mat hashOne, Mat hashTwo)
  33. //
  34. //javadoc: ImgHashBase::compare(hashOne, hashTwo)
  35. public double compare(Mat hashOne, Mat hashTwo) {
  36. ThrowIfDisposed();
  37. if (hashOne != null) hashOne.ThrowIfDisposed();
  38. if (hashTwo != null) hashTwo.ThrowIfDisposed();
  39. #if (UNITY_ANDROID && !UNITY_EDITOR)
  40. double retVal = img_1hash_ImgHashBase_compare_10(nativeObj, hashOne.nativeObj, hashTwo.nativeObj);
  41. return retVal;
  42. #else
  43. return -1;
  44. #endif
  45. }
  46. //
  47. // C++: void cv::img_hash::ImgHashBase::compute(Mat inputArr, Mat& outputArr)
  48. //
  49. //javadoc: ImgHashBase::compute(inputArr, outputArr)
  50. public void compute(Mat inputArr, Mat outputArr) {
  51. ThrowIfDisposed();
  52. if (inputArr != null) inputArr.ThrowIfDisposed();
  53. if (outputArr != null) outputArr.ThrowIfDisposed();
  54. #if (UNITY_ANDROID && !UNITY_EDITOR)
  55. img_1hash_ImgHashBase_compute_10(nativeObj, inputArr.nativeObj, outputArr.nativeObj);
  56. return;
  57. #else
  58. return;
  59. #endif
  60. }
  61. #if (UNITY_ANDROID && !UNITY_EDITOR)
  62. const string LIBNAME = "opencvforunity";
  63. // C++: double cv::img_hash::ImgHashBase::compare(Mat hashOne, Mat hashTwo)
  64. [DllImport(LIBNAME)]
  65. private static extern double img_1hash_ImgHashBase_compare_10(IntPtr nativeObj, IntPtr hashOne_nativeObj, IntPtr hashTwo_nativeObj);
  66. // C++: void cv::img_hash::ImgHashBase::compute(Mat inputArr, Mat& outputArr)
  67. [DllImport(LIBNAME)]
  68. private static extern void img_1hash_ImgHashBase_compute_10(IntPtr nativeObj, IntPtr inputArr_nativeObj, IntPtr outputArr_nativeObj);
  69. // native support for java finalize()
  70. [DllImport(LIBNAME)]
  71. private static extern void img_1hash_ImgHashBase_delete(IntPtr nativeObj);
  72. #endif
  73. }
  74. }