import cv2
import numpy as np
import pytesseract
def resize(image, width=None, height=None, inter=cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
if width is None and height is None:
return image
if width is None:
r = height / float(h)
dim = (int(w * r), height)
else:
r = width / float(w)
dim = (width, int(h * r))
resized = cv2.resize(image, dim, interpolation=inter)
return resized
# 获取坐标点
def order_points(pts):
# 一共4个坐标点
rect = np.zeros((4, 2), dtype="float32")
# 按顺序找到对应坐标0123分别是 左上,右上,右下,左下
# 计算左上,右下
s = pts.sum(axis=1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]
# 计算右上和左下
diff = np.diff(pts, axis=1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]
return rect
def four_point_trans
实战二、OpenCv实现文本扫描
最新推荐文章于 2024-08-01 02:09:04 发布
本文详细介绍了如何使用Python的OpenCV库进行图像处理,包括图像缩放、灰度处理、边缘检测、轮廓检测,以及如何运用透视变换技术,最终实现扫描结果的二值化处理。
摘要由CSDN通过智能技术生成