Skip to content

Error in imdecode, acts differently than imread and doesn't things like orientation and more correctly #8172

Closed

Description

@NinnOgTonic
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.

Activity

  1. mshabunin commented on Feb 20, 2017

    @mshabunin
    Contributor

    The EXIF orientation support has been implemented for imread only.

  2. brian-armstrong-discord commented on Mar 29, 2017

    @brian-armstrong-discord
    Contributor

    Having imdecode do this would be really useful

  3. NinnOgTonic commented on Mar 29, 2017

    @NinnOgTonic
    Author

    indeed, having to write the file from memory to disk, to then create a fh to get the correct effect is an insane work around for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions