mirror of
https://github.com/opencv/opencv.git
synced 2026-07-23 04:13:04 +04:00
66e5fce928
Extend image I/O API with metadata support #27499 Covered with the PR: * AVIF encoder can write exif, xmp, icc * AVIF decoder can read exif * JPEG encoder can write exif * JPEG decoder can read exif * PNG encoder can write exif * PNG decoder can read exif This PR is a sort of preamble for #27488. I suggest to merge this one first to OpenCV 4.x, then promote this change to OpenCV 5.x and then provide extra API to read and write metadata in 5.x (or maybe 4.x) in a style similar to #27488. Maybe in that PR exif packing/unpacking should be done using a separate external API. That is, metadata reading and writing can/should be done in 2 steps: * [1] pack and then [2] embed exif into image at the encoding stage. * [1] extract and then [2] unpack exif at the decoding stage. ### Pull Request Readiness Checklist 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. - [ ] The feature is well documented and sample code can be built with the project CMake
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
'''
|
|
Test for imread
|
|
'''
|
|
|
|
# Python 2/3 compatibility
|
|
from __future__ import print_function
|
|
|
|
import cv2 as cv
|
|
import numpy as np
|
|
import sys
|
|
|
|
from tests_common import NewOpenCVTests
|
|
|
|
class imread_test(NewOpenCVTests):
|
|
def test_imread_to_buffer(self):
|
|
path = self.extraTestDataPath + '/cv/shared/lena.png'
|
|
ref = cv.imread(path)
|
|
|
|
img = np.zeros_like(ref)
|
|
cv.imread(path, img)
|
|
self.assertEqual(cv.norm(ref, img, cv.NORM_INF), 0.0)
|
|
|
|
def test_imread_with_meta(self):
|
|
path = self.extraTestDataPath + '/highgui/readwrite/testExifOrientation_1.jpg'
|
|
img, meta_types, meta_data = cv.imreadWithMetadata(path)
|
|
self.assertTrue(img is not None)
|
|
self.assertTrue(meta_types is not None)
|
|
self.assertTrue(meta_data is not None)
|
|
|
|
path = self.extraTestDataPath + '/highgui/readwrite/testExifOrientation_1.png'
|
|
img, meta_types, meta_data = cv.imreadWithMetadata(path)
|
|
self.assertTrue(img is not None)
|
|
self.assertTrue(meta_types is not None)
|
|
self.assertTrue(meta_data is not None)
|
|
|
|
if __name__ == '__main__':
|
|
NewOpenCVTests.bootstrap()
|