CameraParameters.cs 2.4 KB

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