How to determine if a photo is corrupted?

后端 未结 4 1285
庸人自扰
庸人自扰 2020-12-07 04:05

I have a requirement where in I have to determine whether a photo is corrupted and accordingly tag it as such.

Another thing, I need is to determine if an Image has

4条回答
  •  误落风尘
    2020-12-07 04:40

    I have handled this situation by reading the suspicious image and trying to getting its shape. The task is done within try-except block. Following is the code:

    import cv2
    
    image = cv2.imread('./image.jpg')
    
    try:
        dummy = image.shape # this line will throw the exception
    except:
        print("[INFO] Image is not available or corrupted.")
    

    This approach should cover all your needs like:

    • Detecting a corrupted image
    • Non-image file with an image-type extension detection
    • Missing image detection etc.

提交回复
热议问题