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
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")