[!Here is the picture drawing**]**(https://i.stack.imgur.com/3jY0d.jpg)I'm working on a project where I need to extract the information that exists on this image. There are nodes and dimensions and between 2 nodes there is a dimension, I want to extract this information and store it in an excel file i.e. I need 3 columns. The first column is called from ie the name of the starting node and the second column is the name of the arrival node and the 3rd column is dimension. I have node position and dimension position.
How I can link each 2 nodes with their dimension and store them in an excel file. please help me
the text in blue represents the name of the nodes and in black the dimension.
Here is the code I used to detect and extract the nodes.
import cv2
import numpy as np
import easyocr
import pandas as pd
# Load image
img = cv2.imread("black_lines_result2.jpg")
# Convert to HSV color space
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Set blue color range in HSV
lower_blue = np.array([90, 50, 50])
upper_blue = np.array([130, 255, 255])
# Filter blue color pixels in image
mask = cv2.inRange(hsv, lower_blue, upper_blue)
img=cv2.imwrite('text blue.jpg',mask)
img=cv2.imread('text blue.jpg')
reader = easyocr.Reader(['en'], gpu = True)
results = reader.readtext(img)
df=pd.DataFrame(results,columns=['bbox','text','confidence'])
print(df)
Here is the code to extract the dimension
import cv2
import numpy as np
import easyocr
import pandas as pd
# Charger l'image
img = cv2.imread("black_lines_result2.jpg")
# Convertir en espace de couleur HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Définir la plage de couleurs noires en HSV
lower_black = np.array([0, 0, 0])
upper_black = np.array([180, 255, 30])
# Filtrer les pixels de couleur noire dans l'image
mask = cv2.inRange(hsv, lower_black, upper_black)
cv2.imwrite('noir.jpg',mask)
# Appliquer un traitement morphologique pour améliorer les résultats de détection
kernel = np.ones((3, 3), np.uint8)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
# Inverser les couleurs de l'image pour obtenir du texte blanc sur fond noir
inverted_mask = cv2.bitwise_not(mask)
# Utiliser EasyOCR pour détecter le texte
reader = easyocr.Reader(['en'], gpu=True)
results = reader.readtext(inverted_mask)
# Créer un DataFrame avec les résultats
data = pd.DataFrame(results, columns=['bbox', 'text', 'confidence'])
4# Parcourir chaque élément de la colonne 'text'
for i, text in enumerate(data['text']):
# Supprimer les textes qui ne contiennent que des alphabets
# Supprimer les textes qui ont une longueur supérieure à 10 caractères
if len(text) > 3:
data.drop(i, inplace=True)
print(data)