Я хочу извлечь только части графика из этого изображения в Python, как мне это сделать?Python

Программы на Python
Anonymous
Я хочу извлечь только части графика из этого изображения в Python, как мне это сделать?

Сообщение Anonymous »

Я хочу извлечь два графика справа вместе, и оба по отдельности не могут быть извлечены как один (Изображение)
Я не уверен, что попробовать, я новичок в этом. Я использую Python, извлек текст из изображения и сохранил его в формате CSV
import cv2
import numpy as np

# Load the image
image_path = r'C:\Prarthana\PROJECTS\GitHub\MajorProject\Images\1.jpg'
image = cv2.imread(image_path)

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

# Apply Gaussian blur to reduce noise
blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# Apply Canny edge detection
edges = cv2.Canny(blurred, 50, 150)

# Find contours in the edge-detected image
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Filter contours based on area to find the largest contour (assuming the graph is the largest area)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:1]

# Create a mask to extract the graph region
mask = np.zeros_like(gray)
cv2.drawContours(mask, contours, -1, (255, 255, 255), thickness=cv2.FILLED)

# Apply the mask to the original image to extract the graph
graph = cv2.bitwise_and(image, image, mask=mask)

# Save the extracted graph image
cv2.imwrite(r'C:\Prarthana\PROJECTS\GitHub\MajorProject\Images\output\extracted_graph.jpg', graph)


Подробнее здесь: https://stackoverflow.com/questions/782 ... o-i-go-abo

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