ROI (область интереса) показывает две линии внутри одной ограничивающей рамки на изображении.Python

Программы на Python
Гость
ROI (область интереса) показывает две линии внутри одной ограничивающей рамки на изображении.

Сообщение Гость »

Я пытаюсь идеально распознать каждую строку с помощью полей ROI на изображении на хинди. Но проблема в том, что две строки с большим жирным текстом находятся внутри одной и той же рентабельности инвестиций. Вы можете увидеть на изображении ниже -
Изображение

Исходное изображение —
Изображение
Каждая строка должна точно распознаваться как отдельная строка. Вот исходный код -
import cv2
from google.colab.patches import cv2_imshow
import numpy as np

if __name__ == "__main__":
image = cv2.imread('datasets/0010_jpg.rf.e7741188a2afa6db3dee4324e8486a34.jpg')

# Display the image
# cv2_imshow(image)

# Convert image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# cv2_imshow(gray)

# Convert grayscale image to binary
ret, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY_INV)
# cv2_imshow(thresh)

# Apply Canny edge detection
edges = cv2.Canny(thresh, 50, 150) # Adjust the threshold values as needed
# cv2_imshow(edges)

# Dilation
kernel = np.ones((5, 200), np.uint8)
img_dilation = cv2.dilate(edges, kernel, iterations=1)
# cv2_imshow(img_dilation)

# Find contours
contours, hierarchy = cv2.findContours(img_dilation.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Sort contours based on their bounding box coordinates
bounding_boxes = [cv2.boundingRect(ctr) for ctr in contours]
sorted_contours = [ctr for _, ctr in sorted(zip(bounding_boxes, contours), key=lambda pair: pair[0][1])]

# Loop over sorted contours
for i, ctr in enumerate(sorted_contours):
# Get bounding box
x, y, w, h = cv2.boundingRect(ctr)

# Getting ROI
roi = image[y:y+h-5, x:x+w]
roi_row = roi.shape[0]
roi_col = roi.shape[1]

# Show ROI
if(roi_row>3000 or roi_row

Подробнее здесь: https://stackoverflow.com/questions/781 ... x-in-image

Вернуться в «Python»