Я приложил образец PDF-файла.


Я хочу, чтобы флаг сетки был обнаружен или нет
Я пробовал использовать приведенный ниже код:
import cv2
import pdfplumber
import numpy as np
def is_grid_table(pdf_path):
flag = False # Initialize flag for grid detection
with pdfplumber.open(pdf_path) as pdf:
for page in pdf.pages:
# Extract the image of the page
image = page.to_image()
# Convert the image to a numpy array
image_np = np.array(image.original)
# Convert to grayscale
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
# Apply edge detection
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
# Detect lines using Hough Transform
lines = cv2.HoughLines(edges, 1, np.pi/180, 200)
# Check if lines are detected
if lines is not None:
flag = True # Grid detected
break
return flag
# Example usage
pdf_path = "/home/jainam/Desktop/wfh/layout/OneDrive_1_6-11-2024/hdfc/hdfc_0.pdf"
flag = is_grid_table(pdf_path)
print("Grid Detected:" if flag else "No Grid Detected")
Подробнее здесь: https://stackoverflow.com/questions/793 ... a-table-or