小编Ami*_*rma的帖子

如何旋转图像以对齐文本以进行提取?

我正在使用 pytessearct 从图像中提取文本。但它不适用于倾斜的图像。考虑下面给出的图像:

图片

这是提取文本的代码,它在不倾斜的图像上工作正常。

img = cv2.imread(<path_to_image>)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5,5),0)
ret3, thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
def findSignificantContours (img, edgeImg):
    contours, heirarchy = cv2.findContours(edgeImg, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
    # Find level 1 contours
    level1 = []
    for i, tupl in enumerate(heirarchy[0]):
        # Each array is in format (Next, Prev, First child, Parent)
        # Filter the ones without parent
        if tupl[3] == -1:
            tupl = np.insert(tupl, 0, [i])
            level1.append(tupl)
    significant = []
    tooSmall = edgeImg.size * 5 / 100 # …
Run Code Online (Sandbox Code Playgroud)

python opencv tesseract machine-learning computer-vision

5
推荐指数
1
解决办法
358
查看次数