Closed Pitt64 closed 3 years ago
I am also facing similar issue, my images are also rotated automatically and hence It gives wrong annotation coordinates.
Weird, I haven't experienced this issue myself. Do you mind posting an example for us to test w/?
Here are some examples of the problem:
I managed to find a solution to put the images right by modifying the exif metadata with this command: exiftran -ai *.jpg
This command will change the exif metadata of all jpg files in the current directory to turn them 90° right.
I also realized this issue, which makes my trained model incorrect. Here is my example of this issue ,the two images are the same actually.
@Pitt64 hi,did you take these pictures with your phone? I take my photos with my iphone6 and I find that if I upload the photos with data cable,the image in labelImg always takes the left side of my phone as its bottom. But when I upload photos with wechat(a chinese social software), there is no rotation when I use labelImg. I just wonder if your situation is the same as mine
When a picture is taken with some camera, it is recorded as a landscape direction picture and it is specified in the EXIF file of the picture that it was a portrait direction picture. labelImg isn't handling the rotation needed through that EXIF file.
You have to rotate and save the pictures before using them in labelImg.
You can use
On Linux : exiftran -ai *.jpeg exiftran On Windows: JPEG Autorotate
I have a similar issue. I decided to go through every image and right click and rotate either left or right depending on what that image needed until all images were orientated the correct way, however this didn't seem to work and labelImg is still showing them in the old rotations. I even restarted my computer just to be sure the orientation wasn't getting updated or something like that but no, when I view the images as "extra large icons" they are rotated in the correct fashion, but when I re-open labelImg it is still showing the wrong orientations. I have almost a thousand images, some of them need a clockwise rotation, others need a counterclockwise rotation so I can't rotate them all in one direction with one command. I have no idea why manually rotating images in the file didn't work
update, I seem to have found something that sorta works just by combining bits and pieces of code I found everywhere(assuming you already manually went through and rotated each image). For some reason it gives errors for some images, but for now the try statement just ignores those, I'll try to figure out why later:
`import os import glob import PIL import sys from PIL import Image, ExifTags orig_dir = "C:\Users\path_to_origional_images" conv_dir = "C:\Users\path_to_new_folder_to_store_images\" # make sure to have \ at the end
photos = glob.glob(orig_dir + '/*.jpg') total_pictures = len(photos) print("total number of photos is: " + str(total_pictures)) k = 0 for photo in photos: try: k = k+1 print(photo)
if not os.path.isfile(photo):
continue
im = Image.open(photo)
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation] == "Orientation":
break
exif=dict(im._getexif().items())
if exif[orientation] == 3:
im=im.rotate(180, expand=True)
elif exif[orientation] == 6:
im=im.rotate(270, expand=True)
elif exif[orientation] == 8:
im=im.rotate(90, expand=True)
im.save(conv_dir +str(k)+ ".png")
im.close()
except:
print("caught error")`
I opened each image in MS Paint, saved it, and closed it. That seemed to properly orient the image in labelimg
A good solution was given by @Sasha1296 above and it perfectly solves the rotation problem in LabelImg. For more detailed info, you can refer to the two links about how to access ExifTags and rotate photos.
https://stackoverflow.com/questions/4228530/pil-thumbnail-is-rotating-my-image
https://stackoverflow.com/questions/13872331/rotating-an-image-with-orientation-specified-in-exif-using-python-without-pil-in
I meet the same problem, the picture changed when i open it in labelImg. beside this issue, i find another closed issue Rotate 90° when opening? #342
the key of this problem is because the jpeg image have the metadata exif in wiki, some camera equipment will save the direction sensor's info and some tools will use this meta. obviously labelImg do it
one solution is mentioned above @humandotlearning , use exiftran to change it
another solution is to change the jpeg image to png before you anno it
by the way, i tried several tools to open the jpeg image , some use it and some do not use it. for example, labelImg and vscode parse the exif meta; but opencv (cv2.imread) and ubuntu's image tool do not parse
@Pitt64 , I found what was the problem ! When a picture is taken with some camera, it is recorded as a landscape direction picture and it is specified in the EXIF file of the picture that it was a portrait direction picture. labelImg isn't handling the rotation needed through that EXIF file.
You have to rotate and save the pictures before using them in labelImg. Following are some links to rotate pics to portrait.
You can use
On Linux : https://linux.die.net/man/1/exiftran On Windows: https://savolai.net/software/jpeg-autorotate/
exiftran -ai *.jpg
how did you use that command ? mine not working from gitbash on that folder
Could you please add "rotate image" feature. I'm not sure if the application takes into account the exif metadata of the image; in my case the image is 480x640 and is always rotated to landscape format 640x480 to the left after loading.