paddle检测文本框斜率,矫正,paddleHub提取图片信息
import numpy as np
import cv2
import paddlehub as hub
import math
import datetime
import torch
import os
def rot2(x1,x2,y1,y2):
# k = -(y2 - y1) / (x2 - x1)
k = -(y2 - y1) / (x2 - x1)
# 求反正切,再将得到的弧度转换为度
result = np.arctan(k) * 57.29577
print("直线倾斜角度为:" + str(result) + "度")
return float(result)
# 逆时针旋转图像degree角度(原尺寸)
def rotateImage(src, degree):
# 旋转中心为图像中心
h, w = src.shape[:2]
# 计算二维旋转的仿射变换矩阵
RotateMatrix = cv2.getRotationMatrix2D((w / 2.0, h / 2.0), degree, 1)
#print(RotateMatrix)
# 仿射变换,背景色填充为白色
rotate = cv2.warpAffine(src, RotateMatrix, (w, h), borderValue=(255, 255, 255))
return rotate
#检测文本框数量
def rotate_bound_white_bg(imageMat):
text_detector = hub.Module(name="chinese_text_detection_db_mobile")
text_detector.__init__(enable_mkldnn=True)
#获取文本框
results = text_detector.detect_text(
images=[imageMat],