Detect if a text image is upside down

后端 未结 4 1649
孤城傲影
孤城傲影 2021-01-31 03:06

I have some hundreds of images (scanned documents), most of them are skewed. I wanted to de-skew them using Python.
Here is the code I used:

import numpy a         


        
4条回答
  •  没有蜡笔的小新
    2021-01-31 03:08

    If you have face on image then its easy to detect. I created below code to detect if face is upside down. In upside down case we are not getting face-encodings.

    # first install face_recognition
    # pip install --upgrade face_recognition
    def is_image_upside_down(img):
        import face_recognition
        face_locations = face_recognition.face_locations(img)
        encodings = face_recognition.face_encodings(img, face_locations)
        image_is_upside_down = (len(encodings) == 0)
        return image_is_upside_down
    
    import cv2
    filename = 'path_to_filename'
    # Load file, converting to grayscale
    img = cv2.imread(filename)
    if is_image_upside_down(img):
        print("rotate to 180 degree")
    else:
        print("image is straight")
    
    

提交回复
热议问题