I have an image with marked points of the most top coordinate and most left coordinate and I need to find the corresponding text from that coordinate to get the length of that line.
I am not allowed to use the original image so I tried to recreate it. I need to get 1700 under the blue coordinate and 2777 under the red coordinate to find the size of each side. right now I have the coordinates of the point and I was thinking about making an ROI around that point and find text in that ROI but I have no idea how to do this.
right now i get the outermost points like this:
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])
I only need to know the text next to the top and left coordinates so I can use that text as an output for the size of the blueprint.
Use tesseract's hOCR or tsv output mode so you can get the coordinates of each extracted word/number (maybe limit the extraction characters to extract only digits)
tsv is probably easier to parse, once you have a list in python of every word/number and the corresponding coordinates, iterate that list to find the word that has the least distance to the points, just use euclidean distance.
The closest word/number is probably the one you're looking for
You'll probably need to do this twice, once for the red point and once for the blue point, with a 90º rotated image