Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in opencv 4.11 when reading double precision matrix data from yaml files #1078

Open
lostoliv opened this issue Jan 23, 2025 · 0 comments

Comments

@lostoliv
Copy link

Reading this yaml file in opencv 4.10 works while failing with opencv 4.11 (all int values like 0 get corrupted in 4.11 - while 0.0 is fine):

%YAML:1.0
matrix1:
  rows: 1
  cols: 4
  dt: d
  data: [ 0, 0.0, 1, 1.0 ]

Note that changing dt: d to dt: f works fine.

You can run the following code to repro (assert failing only with 4.11):

# Good: python -m pip install --upgrade opencv-python==4.10.0.84
# Bad:  python -m pip install --upgrade opencv-python==4.11.0.86
import cv2, numpy as np
mat_str = '[ 0, 0.0, 1, 1.0 ]'
yaml_file =\
'%YAML:1.0\n'\
'matrix1:\n'\
'  rows: 1\n'\
'  cols: 4\n'\
'  dt: d\n'\
f'  data: {mat_str}\n'
node_name = 'matrix1'
fs = cv2.FileStorage(yaml_file, cv2.FILE_STORAGE_MEMORY)
mat = fs.getNode(node_name).mat().flatten()
expected = np.array(eval(mat_str))
print(f'mat from yaml: {mat}')
print(f'mat expected:  {expected}')
assert np.allclose(mat, expected)

I see some changes related to FileStorage in 4.11 (like opencv/opencv#26434) that might have introduced this regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant