<p dir="auto">Hi again :)</p>
<p dir="auto">I've noticed that <code class="notranslate">imdecode</code> does not perform the same EXIF-based autorotation that <code class="notranslate">imread</code> does. Having dug through the implementation some, it seems that this is because the <code class="notranslate">ExifReader</code> is filename-based. It would be really handy to add another code path for in-memory images that can look for EXIF data and then transpose/flip them accordingly.</p>
<p dir="auto">Thanks!</p>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 3.1.0</li>
<li>Operating System / Platform =&gt; Ubuntu 16.04.1 LTS</li>
<li>Compiler =&gt; gcc version 5.4.0 20160609</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">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:</p>
<p dir="auto"><code class="notranslate">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</code></p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Load the file like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)"><pre class="notranslate"><code class="notranslate">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)
</code></pre></div>
<p dir="auto">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.</p>