text stringlengths 0 489 |
|---|
i want to create a fastapi solution that follow the logic of the flow path and extract text using paddleocr from all flowchart elements following the start point until the end point comes. |
there might be multiple seperate flowpaths each having its own start point and end point. |
there might be multiple flowpaths in the same image, i need you to extract text from all such paths understanding the workflow progression for each of them and create flow-story based on the extraction. |
the fast api system should take some input from the user to make the task easier:- |
1)the image of the flowchart |
2)total number of flowpaths(startpoints) in the image |
3)based on the number of flowpaths ask for the text given on the startpoint of each path(which you can then use to identify the start point of each flowpath and continue to logically move ahead) |
4)approximate number of text elements |
i have already tried this a few times on my own but it is extremly complextask and i faced most problem in detecting all elements and extracting text from all of them. |
my approach was:- |
use contour-opencv for shape and boundry detection for primary identification and assign each detected element an id based dfs backtracking approach from the start element with target of reaching end element. |
then use image preprocessing and batch processing based on the previously assigned ids zoom in to each batch/grid and start searching and extracting for text again continue this until all the text for every flow path has been extracted then proceed to write them in the form of an flow_story.txt |
based on the response of #1, #2, #3 it becomes easier for the code to identify the start |
We are going to break down the problem into several steps: |
We are given an image of a flowchart, the total number of flow paths (start points), the text on each start point, and the approximate number of text elements. |
We will use PaddleOCR to extract text and their bounding boxes from the entire image. |
We will use OpenCV for shape detection to identify the flowchart elements (like rectangles, diamonds, etc.) and their connections. |
We will try to reconstruct the flow paths by starting from the given start points (using the provided text) and then following the connections until we reach an end point. |
We will output the flow story for each path. |
However, note that the problem is complex and the following approach is a simplified version. |
Steps: |
Preprocess the image (convert to grayscale, thresholding, etc.) to enhance shape detection. |
Use OpenCV to find contours (shapes) in the image. We assume that each flowchart element is a rectangle or a diamond (or other shapes) and we will try to approximate the contours to polygons. |
For each contour, we can compute the bounding rectangle and then use PaddleOCR to extract text from that bounding rectangle. Alternatively, we can run PaddleOCR on the entire image and then assign text to the closest contour. |
We are given the start points by the user (by providing the text on each start point). So we can match the provided start text with the extracted text to find the starting elements. |
We need to determine the connections between elements. This can be done by detecting arrows or lines. We can use Hough Line Transform to detect lines and then determine which elements are connected by these lines. |
Once we have the graph of elements (nodes) and connections (edges), we can traverse from each start node until we reach an end node (a node with no outgoing connection or with text that indicates the end). |
During traversal, we collect the text of each node and form the flow story. |
Since the problem is very challenging and the accuracy of shape detection and OCR might vary, we will make some assumptions: |
The flowchart is drawn with clear shapes and lines. |
The text extracted by PaddleOCR is accurate enough to match the user-provided start text. |
We'll use the following libraries: |
OpenCV for image processing and shape detection. |
PaddleOCR for text extraction. |
FastAPI for the web API. |
Let's design the FastAPI endpoint: |
We'll have a POST endpoint that accepts: |
image: file (the flowchart image) |
num_paths: int (number of flow paths) |
start_texts: List[str] (list of text on each start point, in the order of the paths) |
approx_text_elements: int (approximate number of text elements, might be used for validation) |
The response will be a JSON with the flow stories for each path. |
Steps in the code: |
Read the image and preprocess for contour detection. |
Extract contours and approximate them to polygons to get the shapes. |
Extract text and their bounding boxes using PaddleOCR. |
Assign text to the closest contour (if the text bounding box is inside or near the contour). |
Build a graph of the flowchart: nodes are the contours with text, and edges are the connections (lines) between them. |
For each start text, find the corresponding node and then traverse the graph until an end node (a node with no outgoing edges or with text "End"). |
Collect the text of the nodes in the order of traversal. |
However, note that the problem of automatically reconstructing a flowchart from an image is very complex and might not be 100% accurate. |
We'll try a simpler approach: |
We assume that the flowchart elements are rectangles and we are only interested in the text inside them. |
We will not try to detect the arrows and instead rely on the spatial arrangement (left to right, top to bottom) to determine the flow? But this is not always the case. |
Alternatively, we can use the following: |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 12