Files
opencv-MIRROR/modules/core/include
Abhishek Gola 6519977a19 Merge pull request #31103 from wzy712/fix-file_storage_overload
Problem
cv2.FileStorage.write() stores any Python integer outside the int32 range as a
boolean instead of a 64-bit integer: YAML gets true, XML/JSON get 1, and
reading the node back yields 1.0. The write(const String&, int64_t)
overload is exposed to Python but is unreachable.

The C++ API is not affected — FileStorage::write(name, (int64_t)value) stores
the exact value, as already covered by FileStorage_exact_type.long_int in
modules/core/test/test_io.cpp.

Root cause
The Python binding resolves FileStorage::write() overloads in declaration
order (modules/core/include/opencv2/core/persistence.hpp):

CV_WRAP void write(const String& name, int val);
CV_WRAP void write(const String& name, bool val);
CV_WRAP void write(const String& name, int64_t val);
For a Python integer outside int32, pyopencv_to(int&) fails the range check
and pyopencv_to(bool&) (modules/python/src2/cv2_convert.cpp, accepts any
integer scalar) consumes the value before the int64_t overload is tried.

Fix
Declare the int64_t overload before bool.
2026-12-02 16:32:53 +05:30
..