DnnConverters.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if !UNITY_WSA_10_0
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.DnnModule;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace OpenCVForUnity.UtilsModule
  7. {
  8. public partial class Converters
  9. {
  10. public static Mat vector_MatShape_to_Mat(List<MatOfInt> matshapes)
  11. {
  12. Mat res;
  13. int count = (matshapes != null) ? matshapes.Count : 0;
  14. if (count > 0)
  15. {
  16. res = new Mat(count, 1, CvType.CV_32SC2);
  17. int[] buff = new int[count * 2];
  18. for (int i = 0; i < count; i++)
  19. {
  20. long addr = matshapes[i].nativeObj.ToInt64();//TODO:@check
  21. buff[i * 2] = (int)(addr >> 32);
  22. buff[i * 2 + 1] = (int)(addr & 0xffffffff);
  23. }
  24. res.put(0, 0, buff);
  25. }
  26. else
  27. {
  28. res = new Mat();
  29. }
  30. return res;
  31. }
  32. public static void Mat_to_vector_Target(Mat m, List<int> targets)
  33. {
  34. if (m != null)
  35. m.ThrowIfDisposed();
  36. if (targets == null)
  37. throw new CvException("targets == null");
  38. int count = m.rows();
  39. if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
  40. throw new CvException(
  41. "CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m);
  42. targets.Clear();
  43. int[] buff = new int[count];
  44. m.get(0, 0, buff);
  45. for (int i = 0; i < count; i++)
  46. {
  47. targets.Add((int)buff[i]);//TODO:@check
  48. }
  49. }
  50. }
  51. }
  52. #endif