I have following test.yaml:
Camera.ColourOrder: "RGB"
Camera.ColourDepth: "UCHAR_8"
Camera.Spectrum: "Visible_NearIR"
IMU.T_b_c1: !!opencv-matrix
rows: 4
cols: 4
dt: f
data: [0.999903, -0.0138036, -0.00208099, -0.0202141,
0.0137985, 0.999902, -0.00243498, 0.00505961,
0.0021144, 0.00240603, 0.999995, 0.0114047,
0.0, 0.0, 0.0, 1.0]
I am trying to read it using python opencv cv2 module (because it contains opencv related objects like opencv_matrix embedded in yaml, which will give error if tried reading using python's inbuilt yaml module). But it is giving me error as shown below:
>>> import os
>>> 'test.yaml' in os.listdir()
True
>>> import cv2
>>> fs = cv2.FileStorage("test.yaml", cv2.FILE_STORAGE_READ)
cv2.error: OpenCV(4.8.1) /io/opencv/modules/core/src/persistence.cpp:699: error: (-5:Bad argument) Input file is invalid in function 'open'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <class 'cv2.FileStorage'> returned a result with an error set
I tried removing IMU.T_b_c1 and keeping just Camera.xyz values, still the same error. What I am missing here?
PS: is there any other way / module to read such yaml file with embedded opencv objects? I am ok with not using cv2 and read some other package / module.
Judging by the error message and the implementation, OpenCV expects YAML data to be preceded by a YAML directive (%YAML). The directive is also shown in the documentation's sample.
Try the following (notice first line)
%YAML:1.0
Camera.ColourOrder: "RGB"
Camera.ColourDepth: "UCHAR_8"
Camera.Spectrum: "Visible_NearIR"
IMU.T_b_c1: !!opencv-matrix
rows: 4
cols: 4
dt: f
data: [0.999903, -0.0138036, -0.00208099, -0.0202141,
0.0137985, 0.999902, -0.00243498, 0.00505961,
0.0021144, 0.00240603, 0.999995, 0.0114047,
0.0, 0.0, 0.0, 1.0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With