You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yaml_handling.py 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import yaml
  2. from sensor_msgs.msg import CameraInfo
  3. def yaml_to_CameraInfo(yaml_fname):
  4. # Load data from file
  5. with open(yaml_fname, "r") as file_handle:
  6. calib_data = yaml.load(file_handle)
  7. # try to load the parameters
  8. camera_info_msg = CameraInfo()
  9. try:
  10. camera_info_msg.width = calib_data["image_width"]
  11. except:
  12. pass
  13. try:
  14. camera_info_msg.height = calib_data["image_height"]
  15. except:
  16. pass
  17. try:
  18. camera_info_msg.k = calib_data["camera_matrix"]["data"]
  19. except:
  20. pass
  21. try:
  22. camera_info_msg.d = calib_data["distortion_coefficients"]["data"]
  23. except:
  24. pass
  25. try:
  26. camera_info_msg.r = calib_data["rectification_matrix"]["data"]
  27. except:
  28. pass
  29. try:
  30. camera_info_msg.p = calib_data["projection_matrix"]["data"]
  31. except:
  32. pass
  33. try:
  34. camera_info_msg.distortion_model = calib_data["distortion_model"]
  35. except:
  36. pass
  37. return camera_info_msg