Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 533 Bytes

img_full.md

File metadata and controls

25 lines (20 loc) · 533 Bytes

验证图像完整性

from PIL import Image
import os
from tqdm import tqdm
import mmcv
import mmengine.fileio as fileio
def is_image_corrupted(image_path):
    try:
      	# PIL验证
        Image.open(image_path).verify()

        # mmcv验证
        img_bytes = fileio.get(image_path)
        img = mmcv.imfrombytes(img_bytes)
        if img is None:
            return True # 图像损坏
        return False  # 图像未损坏
    except (IOError, SyntaxError) as e:
        return True  # 图像损坏