Какие методы я могу использовать??
Я не хочу создавать свою собственную модель, чтобы сегментировать эти линии. Я ищу другой простой метод.

Вот моя попытка сделать это:
import cv2
import numpy as np
import os
import matplotlib.pyplot as plt
image_path = 'image-samples/input/sample/page_1_gray.png'
print("Loading image from:", image_path)
if not os.path.isfile(image_path):
print("Image file not found:", image_path)
else:
image = cv2.imread(image_path)
if image is None:
print("Failed to load image.")
else:
print("Image loaded successfully:", image.shape)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, binary = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY_INV)
plt.figure(figsize=(10, 5))
plt.imshow(gray, cmap='gray')
plt.title('Grayscale Image')
plt.axis('off')
plt.show()
plt.figure(figsize=(10, 5))
plt.imshow(binary, cmap='gray')
plt.title('Grayscale Image')
plt.axis('off')
plt.show()
kernel = np.ones((5, 15), np.uint8)
morph = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel)
plt.figure(figsize=(10, 5))
plt.imshow(morph, cmap='gray')
plt.title('Morphological Closed Image')
plt.axis('off')
plt.show()
contours, _ = cv2.findContours(morph, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=lambda c: cv2.boundingRect(c)[1])
print("Number of contours detected:", len(contours))
line_segments = []
for i in range(len(contours) - 1):
x1, y1, w1, h1 = cv2.boundingRect(contours)
x2, y2, w2, h2 = cv2.boundingRect(contours[i + 1])
if y2 > (y1 + h1):
segment = image[y1 + h1:y2, x1:x2 + w2] # the region
line_segments.append(segment)
plt.figure(figsize=(10, 5))
plt.imshow(cv2.cvtColor(segment, cv2.COLOR_BGR2RGB))
plt.title(f'Extracted Line Segment {len(line_segments)}')
plt.axis('off')
plt.show()
Подробнее здесь: https://stackoverflow.com/questions/790 ... -documents