CameraParameters.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. using System;
  3. using OpenCVForUnity.CoreModule;
  4. namespace OpenCVForUnityExample
  5. {
  6. [System.Serializable]
  7. public struct CameraParameters
  8. {
  9. public string calibration_date;
  10. public int frames_count;
  11. public int image_width;
  12. public int image_height;
  13. public int calibration_flags;
  14. public double[] camera_matrix;
  15. public double[] distortion_coefficients;
  16. public double avg_reprojection_error;
  17. public CameraParameters (int frames_count, int image_width, int image_height, int calibration_flags, double[] camera_matrix, double[] distortion_coefficients, double avg_reprojection_error)
  18. {
  19. this.calibration_date = DateTime.Now.ToString ();
  20. this.frames_count = frames_count;
  21. this.image_width = image_width;
  22. this.image_height = image_height;
  23. this.calibration_flags = calibration_flags;
  24. this.camera_matrix = camera_matrix;
  25. this.distortion_coefficients = distortion_coefficients;
  26. this.avg_reprojection_error = avg_reprojection_error;
  27. }
  28. public CameraParameters (int frames_count, int image_width, int image_height, int calibration_flags, Mat camera_matrix, Mat distortion_coefficients, double avg_reprojection_error)
  29. {
  30. double[] camera_matrixArr = new double[camera_matrix.total ()];
  31. camera_matrix.get (0, 0, camera_matrixArr);
  32. double[] distortion_coefficientsArr = new double[distortion_coefficients.total ()];
  33. distortion_coefficients.get (0, 0, distortion_coefficientsArr);
  34. this.calibration_date = DateTime.Now.ToString ();
  35. this.frames_count = frames_count;
  36. this.image_width = image_width;
  37. this.image_height = image_height;
  38. this.calibration_flags = calibration_flags;
  39. this.camera_matrix = camera_matrixArr;
  40. this.distortion_coefficients = distortion_coefficientsArr;
  41. this.avg_reprojection_error = avg_reprojection_error;
  42. }
  43. public Mat GetCameraMatrix ()
  44. {
  45. Mat m = new Mat (3, 3, CvType.CV_64FC1);
  46. m.put (0, 0, camera_matrix);
  47. return m;
  48. }
  49. public Mat GetDistortionCoefficients ()
  50. {
  51. Mat m = new Mat (distortion_coefficients.Length, 1, CvType.CV_64FC1);
  52. m.put (0, 0, distortion_coefficients);
  53. return m;
  54. }
  55. }
  56. }