pythonopencvmatplotlibimread

Why the view of some photos read by cv2.imread and plt.imread are different?


I have some photos taken by UAV, and I find that the view of some photos read by cv2.imread and plt.imread are different, one of them is upside down (180° rotation), but most photos are the same.

Why?


Solution

  • Unlike matplotlib (PIL), opencv takes EXIF information into account by default, see documentation:

    If EXIF information is embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flags IMREAD_IGNORE_ORIENTATION or IMREAD_UNCHANGED are passed.

    (to achieve the same with PIL, use exif_transpose)