CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Fix bug with int64 support for FileStorage #26846
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
Fix bug with int64 support for FileStorage #26846
Conversation
dfad11a
to
56ddb98
Compare
Probably, this fix may break compatibility on reading raw data serialized before with 4 bytes per int, doesn't it? |
@MaximSmolskiy, May I also ask you to open a PR with similar patch to 5.x branch? In such way we will test CV_64S Mat read/write too: https://github.com/opencv/opencv/pull/26399/files#diff-cf43289d2308f02754d618a5d975c44123ebb553fe074ccff700c7328a49badfR2078 |
Yes, it is. But I can't think of any example code to do that. Can you please provide one? |
|
Never mind, I just checked that both 5.x and PR produces the same base64 raw data outputs for int32. Thanks for the patch! @staticmethod
def get_normal_2d_mat():
rows = 10
cols = 20
cn = 3
image = np.zeros((rows, cols, cn), np.int32)
image[:] = (1, 2, 127)
for i in range(rows):
for j in range(cols):
image[i, j, 1] = (i + j) % 256
return image
def write_base64_json(self, fname):
fname = "/home/d.kurtaev/test_file.json"
fs = cv.FileStorage(fname, cv.FileStorage_WRITE_BASE64)
mats = {'normal_2d_mat': self.get_normal_2d_mat()}
for name, mat in mats.items():
fs.write(name, mat)
fs.release()
However seems like we should fix int64 base64 write mode later (in a separate PR for sure): diff --git a/modules/python/test/test_filestorage_io.py b/modules/python/test/test_filestorage_io.py
index 01e0a72300..5ef0fd26ee 100644
--- a/modules/python/test/test_filestorage_io.py
+++ b/modules/python/test/test_filestorage_io.py
@@ -124,7 +124,7 @@ class filestorage_io_test(NewOpenCVTests):
cols = 20
cn = 3
- image = np.zeros((rows, cols, cn), np.uint8)
+ image = np.zeros((rows, cols, cn), np.int64)
image[:] = (1, 2, 127)
for i in range(rows):
|
…test_base64-for-64-bit-integer-types Support 64-bit integer types for FileStorage Base64 #26871 ### Pull Request Readiness Checklist Related to #26846 (comment) OpenCV extra: opencv/opencv_extra#1232 See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
…_support_for_FileStorage Fix bug with int64 support for FileStorage opencv#26846 ### Pull Request Readiness Checklist Fix opencv#26829, opencv/opencv-python#1078 In current implementation of `int64` support raw size of recorded integer is variable (`4` or `8` bytes depending on value). But then we iterate over nodes we need to know it exact value https://github.com/opencv/opencv/blob/dfad11aae7ef3b3a0643379266bc363b1a9c3d40/modules/core/src/persistence.cpp#L2596-L2609 Bug is that `rawSize` method still return `4` for any integer. I haven't figured out a way how to get variable raw size for integer in this method. I made raw size for integer is constant and equal to `8`. Yes, after this patch memory consumption for integers will increase, but I don't know a better way to do it yet. At least this fixes bug and implementation becomes more correct See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Pull Request Readiness Checklist
Fix #26829, opencv/opencv-python#1078
In current implementation of
int64
support raw size of recorded integer is variable (4
or8
bytes depending on value). But then we iterate over nodes we need to know it exact valueopencv/modules/core/src/persistence.cpp
Lines 2596 to 2609 in dfad11a
Bug is that
rawSize
method still return4
for any integer. I haven't figured out a way how to get variable raw size for integer in this method. I made raw size for integer is constant and equal to8
.Yes, after this patch memory consumption for integers will increase, but I don't know a better way to do it yet. At least this fixes bug and implementation becomes more correct
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.