-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Error in imdecode, acts differently than imread and doesn't things like orientation and more correctly #8172
Description
System information (version)
- OpenCV => 3.1.0
- Operating System / Platform => Ubuntu 16.04.1 LTS
- Compiler => gcc version 5.4.0 20160609
Detailed description
There appears to be a bug in python cv2.imdecode behaves differently than cv2.imread, imread will correctly detect orientation and load the image properly, meanwhile imdecode will neither detect orientation or load the image properly. I cannot upload the input image itself as it contains sensitive data, but it's a completely standard image from an iPhone 6 with the following meta data (from file), displaying orientation etc:
JPEG image data, Exif standard: [TIFF image data, big-endian, direntries=10, manufacturer=Apple, model=iPhone 6, orientation=upper-right, xresolution=150, yresolution=158, resolutionunit=2, software=10.0.1, datetime=2016:12:01 15:19:20], baseline, precision 8, 3264x2448, frames 3
Steps to reproduce
Load the file like:
fh = open('somefile.jpg', 'r') # or some other way of providing in memory streams, i.e. posted from a webserver
arr = np.asarray(bytearray(fh.read()), dtype=np.uint8)
tmp = cv2.imdecode(arr, -1) # 'load it as it is' or 1 for 3channel
cv2.imwrite('/tmp/loadedfile.jpg', tmp)
This will write the image back incorrectly to the disk, meanwhile if i either write the memory stream to disk and then use imread, it handles orientation and so forth correctly.