Ask Your Question

cv::imread - Camera orientation problem

asked 2016-01-08 17:33:26 -0500

Sid23 gravatar image

updated 2016-01-09 10:05:40 -0500

I'm following this guide here to try out CLAHE in Python, so I have the following code:

import numpy as np
import cv2

img = cv2.imread('t1.JPG',0)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
cl1 = clahe.apply(img)


Before (t1.JPG):

After (t1-clahe.JPG):
image description

So, if you see the links provided, the image has been reshaped. There doesn't seem to be any indication in the guide that this should happen. Am I missing something here? I don't want to reshape the image.

Funny thing is that if I output the shape of the image then there seems to be no change. I get the following:

Before: (2448, 3264)
After: (2448, 3264)

But if you look at the after image, it has clearly been reshaped. I noticed another thing. This problem is only happening with images taken from my iPhone 5S. I tried other images and they did not have the same issue. I tried to find differences between the images that are being reshaped and ones that aren't. So, I noticed the following difference:

reshaped    : JPEG image data, EXIF standard 2.21
not reshaped: JPEG image data, JFIF standard 1.01

Any help with this problem would be greatly appreciated.

OpenCV version being used: 2.4.8

edit retag flag offensive close merge delete



i do not see any reshape here ?

berak gravatar imageberak ( 2016-01-09 03:51:40 -0500 )edit

also, please, for the future, spare us such ridiculous large images

berak gravatar imageberak ( 2016-01-09 03:52:51 -0500 )edit

I guess 'reshape' wasn't the correct terminology for this problem. What I meant was that the 'orientation' has changed. As for the images, I didn't think that they would be imbedded into the notification emails since I provided external links

Sid23 gravatar imageSid23 ( 2016-01-09 09:50:04 -0500 )edit

maybe we should rephrase the whole question (as CLAHE has absolutely nothing to do with it) to "problems with image orientation due to EXIF headers" or the like ?

berak gravatar imageberak ( 2016-01-09 10:03:30 -0500 )edit

@berak i was editing the question when you were commenting. @Sid23 i edited label of the question but it will be better if you rephrase the whole question.

sturkmen gravatar imagesturkmen ( 2016-01-09 10:08:15 -0500 )edit

imho, it's perfect, already ;)

berak gravatar imageberak ( 2016-01-09 10:20:05 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-01-09 06:11:52 -0500

updated 2016-01-09 06:45:55 -0500

just to clarify the question

test code

#include "opencv2/highgui.hpp"

using namespace cv;

int main( int argc, char** argv )
    Mat src1 = imread( "t1.JPG" );
    Mat src2 = imread( "t1-clahe2.JPG" );



    return 0;

screenshot of Windows7 Explorer window image description


Camera orientation handling is newly added to OpenCV

my result is as following reverting Camera orientation handling

image description

edit flag offensive delete link more



yes, you are right. It is due to the camera orientation issue. My version of OpenCV doesn't handle orientation properly. I've found a workaround though, which is good enough for my purposes. Thank you for your help.

Sid23 gravatar imageSid23 ( 2016-01-09 09:46:53 -0500 )edit

Windows7 also doesn't handle orientation properly. what about Windows8,Windows10 and Linux?

sturkmen gravatar imagesturkmen ( 2016-01-09 10:23:44 -0500 )edit

Linux reads the exif data correctly and expects users to handle that, which is actually how it should be.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-11 06:58:07 -0500 )edit

Question Tools

1 follower


Asked: 2016-01-08 15:34:31 -0500

Seen: 2,168 times

Last updated: Jan 09 '16