Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Orientation (python+openCV)

Using Python and OpenCV, I try to read an image which size is (3264*2448), but the resulting size is always (2448*3264). That means the direction of the image is changed by 90 degrees. The code is following:

img1 = cv2.imread("C:\\Users\\test.jpg", 0) 
cv2.namedWindow("test", 0) 
cv2.imshow("test", img1)

the orignal image is this:

enter image description here

but I get this image:

enter image description here

like image 836
yuanyesjtu Avatar asked Jun 14 '17 06:06

yuanyesjtu


People also ask

How do I change the orientation of an image in Python?

rotate() function is used to rotate an image by an angle in Python.

How do you rotate an image 180 degrees in cv2?

We can rotate a given image using OpenCV in two ways. One is using the cv. rotate() function and other is using cv2. getRotationMatrix2D() function.

How do I know the orientation of an image?

The length of the longest side determines the orientation. For example, if the height of the image is longer than the width, it is a “portrait” format. Images where the width is longer are called “landscape.”


1 Answers

I faced a similar issue in one program. In my case, the problem was due to the camera orientation data stored in the image.

The problem was resolved after I used CV_LOAD_IMAGE_COLOR instead of CV_LOAD_IMAGE_UNCHANGED in OpenCV Java.

like image 67
Akshay Mhapankar Avatar answered Sep 29 '22 23:09

Akshay Mhapankar