python-opencv 旋转文本校正

这篇博客介绍了如何利用Python和OpenCV实现基于傅里叶变换的旋转文本校正。作者提供了具体代码,并提到这种方法在单一场景的纯文本中表现良好。同时,文中讨论了opencv图像旋转时的裁切问题和坐标变换。
摘要由CSDN通过智能技术生成

试了下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 
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值