首页 > 解决方案 > 打开简历文本检测

问题描述

在此处输入图像描述

我想在不运行任何OCR 技术的情况下检测每个单词。我的想法是在这张图片中的每个单词周围创建矩形。为了实现这一点,我制作了一个 python 脚本,附在下面,这与我的期望不符。基本上我想:

  1. 在每个单词周围绘制矩形。(我实际上不在乎它是否是一个单词)特别取决于黑色我想绘制矩形,如果黑色非常接近出现,那么我可以假设它是一个单词. 像这样:这个

我的 Python 脚本:

import numpy as np
import cv2


image = cv2.imread('Capture.JPG')
original = image.copy()
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower = np.array([0,0, 0], dtype="uint8")
upper = np.array([200,200, 200], dtype="uint8")
mask = cv2.inRange(image, lower, upper)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)

cnts = cv2.findContours(opening, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

area = 0
for c in cnts:
    area += cv2.contourArea(c)
    cv2.drawContours(original,[c], 0, (0,0,0), 1)
    x, y, w, h = cv2.boundingRect(c)
    color = list(np.random.random(size=3) * 256)
    cv2.rectangle(original, (x, y), (x + w, y + h), color, 1)

    print(c)
print(area)
cv2.imshow('mask', mask)
cv2.imshow('original', original)
cv2.imshow('opening', opening)
cv2.waitKey()

标签: pythonopencvcv2

解决方案


推荐阅读