X-AnyLabeling icon indicating copy to clipboard operation
X-AnyLabeling copied to clipboard

ai预测框漂移

Open yzxiu opened this issue 1 year ago • 4 comments

系统是kde neon,基于ubuntu22.04

ai自动标注的时候,有些框的大小是对的,但是位置有些漂移

图片 图片

yzxiu avatar Jan 18 '24 05:01 yzxiu

@yzxiu, Hi, may I kindly request you to package the images where the result is abnormal and send them to the email [email protected] for further investigation?

CVHub520 avatar Jan 18 '24 06:01 CVHub520

@CVHub520 At first I thought it had something to do with the zoom rate, tried 150% 100% and had similar problems. Some of the image boxes are realistically normal, and some of the images appear to be drifting. 图片

datasets: https://download.openmmlab.com/mmyolo/data/cat_dataset.zip

yzxiu avatar Jan 18 '24 06:01 yzxiu

Hello,

This issue is not related to your system environment. According to the images you provided, after checking, it was found that some images had been rotated. Specifically, you can refer to #198.

You can simply check the current image's EXIF information with the following script:

from PIL import Image, ExifTags

def get_exif_data(image_path):
    try:
        with Image.open(image_path) as img:
            exif_data = img._getexif()
            if exif_data is not None:
                print("EXIF Information:")
                for tag, value in exif_data.items():
                    tag_name = ExifTags.TAGS.get(tag, tag)
                    print(f"{tag_name}: {value}")
            else:
                print("No EXIF information found.")
    except Exception as e:
        print(f"Error: {e}")

image_path = "cat_dataset/images/IMG_20210627_225110.jpg"


get_exif_data(image_path)

So as an auxiliary solution, you can simply use the following script to convert the images to a normal state:

from PIL import Image, ExifTags
import os

def rotate_images_in_folder(folder_path):
    for filename in os.listdir(folder_path):
        if filename.endswith(('.jpg', '.jpeg', '.png')):
            image_path = os.path.join(folder_path, filename)
            rotate_image(image_path)

def rotate_image(image_path):
    try:
        with Image.open(image_path) as img:
            exif_data = img._getexif()
            for tag, value in exif_data.items():
                tag_name = ExifTags.TAGS.get(tag, tag)
                if tag_name != "Orientation":
                    continue
                if value == 3:
                    img = img.rotate(180, expand=True)
                elif value == 6:
                    img = img.rotate(270, expand=True)
                elif value == 8:
                    img = img.rotate(90, expand=True)
                img.save(image_path)
                print(f"Image {image_path} rotated successfully.")
            else:
                print(f"No rotation needed for {image_path}.")
    except Exception as e:
        print(f"Error processing {image_path}: {e}")

folder_path = "/home/cvhub/workspace/tmp/20240118/cat/cat_dataset/images"
rotate_images_in_folder(folder_path)

Finally, re-import into the tool for annotation.

Good luck!

CVHub520 avatar Jan 18 '24 07:01 CVHub520

@CVHub520 Thank you for your project, and thank you for your response. I am going to study the content you mentioned.

yzxiu avatar Jan 18 '24 07:01 yzxiu

@CVHub520

https://github.com/CVHub520/X-AnyLabeling/blob/cc16c69d303bd3f537221e6c53665a181202c1c4/anylabeling/views/labeling/utils/opencv.py#L14-L28

既然从磁盘路径直接读取图片暂时存在图片旋转的问题,为什么不优先使用 qt_img 呢?

yzxiu avatar Feb 05 '24 02:02 yzxiu