【发布时间】:2020-01-18 05:18:08
【问题描述】:
我有一个带有最顶部坐标和最左侧坐标的标记点的图像,我需要从该坐标中找到相应的文本以获取该行的长度。
我不允许使用原始图像,所以我尝试重新创建它。我需要在蓝色坐标下得到 1700,在红色坐标下得到 2777 才能找到每一边的大小。现在我有该点的坐标,我正在考虑围绕该点创建一个 ROI 并在该 ROI 中查找文本,但我不知道该怎么做。
现在我得到这样的最外点:
import cv2
import numpy as np
image = cv2.imread('assets/bpcrop_3.png')
blur = cv2.GaussianBlur(image, (3,3), 0)
gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 220, 255, cv2.THRESH_BINARY_INV)
kernel = np.ones((3,3), np.uint8)
dilation = cv2.dilate(thresh, kernel, iterations=35)
cnts = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
c = max(cnts, key=cv2.contourArea)
left = tuple(c[c[:, :, 0].argmin()][0])
right = tuple(c[c[:, :, 0].argmax()][0])
top = tuple(c[c[:, :, 1].argmin()][0])
bottom = tuple(c[c[:, :, 1].argmax()][0])
我只需要知道顶部和左侧坐标旁边的文本,以便我可以使用该文本作为蓝图大小的输出。
【问题讨论】:
标签: python opencv image-processing ocr python-tesseract