We are working on Tensorflow to train a dataset of images. To get images we record video using our phones and, using OpenCV in Python we extract each frame and save them as JPG images. I rotate some of them to portrait mode with the Photos App on Windows 10.

Then, we have our own annotation tool written in Java to label each item we see on the images. It return a CSV file for each object with their coordinates (in percentage).

However, when I ran the training yesterday, I noticed via the tensorboard interface that some were not annotated rightly (the ones I rotated with Photos)

Here is the image opened on Tensorboard, you can see that the can is very badly annotated.

Image on tensorboard

It turns out that if I open this image with our Java software it is well annotated, but as you can see below, the image is horizontal (it doesn't take in account the rotation applied with Photos) :

Image via the Java tool

If I open it with Paint, or the explorer it appears in portrait mode like in tensorboard.

An other fact, If I send the picture via Facebook, and download it again, it will appear in portrait mode on the Java tool as it would have been from the beginning.

I tried to rotate the image with Paint this time, and it appears correctly in the Java tool.

The code that displays the image in Java:

panel.image = New File(srcFile);

The code that saves video frame in Python:

cap = cv.VideoCapture(video_path)
while cap.isOpened():
    ret, frame = cap.read()
    if ret:
        try:
            cv.imwrite(output_img_path, frame)
        except Exception:
            pass
    else:
        break
cap.release()

Do you know why Java ignores the rotation applied via the Win10 Photos software, why it works via Paint ?

Is there a way to make Java take it in account because it would be very unpleasant to start again from scratch.

Thanking you in advance,

1 Answers

0
Cybermate On

After noticing that rotating images with Paint instead of Photos was giving what we wanted, I found out what was wrong.

"If you’re using Windows 10, File Explorer and the default image viewer will properly obey the Exif Orientation tag, so photos that come from your smartphone or digital camera will be display properly. Google’s Android and Apple’s iOS both natively create photos with the Exif Orientation tag and support it." (source)

I used JPG autorotate to fix this.