python - 打开简历文本检测
问题描述
我想在不运行任何OCR 技术的情况下检测每个单词。我的想法是在这张图片中的每个单词周围创建矩形。为了实现这一点,我制作了一个 python 脚本,附在下面,这与我的期望不符。基本上我想:
我的 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()
解决方案
推荐阅读
- php - 计算php中的子数组
- ios - Swift - 将 Google AdMob 与我的应用程序集成时遇到问题
- python - 如何在 Tkinter Python 中的 .place() 几何方法中的条目小部件中使用 ipadx 和 ipady
- asp.net - 基于数据库查询asp.net vb从服务器中删除文件
- node.js - 使用正确的 oauth2 凭据通过 NodeJS 使用 Passport.js 连接到 AzureDevops
- python - 如何在 loc 返回的列中获取行的子字符串?
- r - 数据表 R 中的调色板
- typescript - TypeScript 中只读的不可变数据
- mysql - 使用 REPLACE 函数而不是 CASE 语句时 MySQL 查询运行缓慢
- jquery - Quill 编辑器和 Flexbox 元素