最近在网上下了一批jpg图片作为训练集,发现使用opencv的imread读取图片时总是出现Premature end of JPEG file报错,查找了网上资料发现时jpg图像受损导致,遂问gpt写了一段代码用以检测错误图片:
import os
import cv2
from skimage.io import imread
def check_image_integrity(image_path):
try:
img = imread(image_path)
return False
except Exception <

本文介绍了一个Python脚本,使用OpenCV和skimage库来检测文件夹中jpg图片的完整性,当遇到PrematureendofJPEGfile错误时,识别出受损图片和可正常加载的图片。
最低0.47元/天 解锁文章
3574






