试了下OpenCV实现基于傅里叶变换的旋转文本校正的方法,对于场景单一的纯文本效果还行,用python-opencv进行了重写,代码如下
import cv2
import numpy as np
from math import *
def rotate_lh(img,degree):
height_ori,width_ori=img.shape[:2]
height_1=int(width_ori*fabs(sin(radians(degree)))+height_ori*fabs(cos(radians(degree))))
width_1=int(height_ori*fabs(sin(radians(degree)))+width_ori*fabs(cos(radians(degree))))
matRotation=cv2.getRotationMatrix2D((width_ori/2,height_ori/2),degree,1)
matRotation[0,2] +=(width_1-width_ori)/2
matRotation[1,2] +=(height_1-height_ori)/2
imgRotation=cv2.warpAffine(img,matRotation,(width_1,height_1),borderValue=(255,255,255))
return imgRotation
def docRot(filename):
srcImg = cv2.imread(filename, cv2.IMREAD_GRAYSCALE);
if(srcImg is None):
return