|
OCR Project
|
Letter segmentation: detect crossword grid and extract letter cells. More...
#include <stddef.h>

Go to the source code of this file.
Classes | |
| struct | BoundingBox |
| Axis-aligned bounding box of one letter cell. More... | |
| struct | SegmentResult |
| Result of a grid detection / segmentation pass. More... | |
Functions | |
| SegmentResult * | segment_image (const unsigned char *pixels, int width, int height) |
| Segment a binarised image into letter cell bounding boxes. | |
| int | segment_detect_grid (const unsigned char *pixels, int width, int height, float min_span, SegmentResult *out) |
| Detect grid lines and infer cell geometry. | |
| int | segment_connected_components (const unsigned char *pixels, int width, int height, SegmentResult *out) |
| Extract letter bounding boxes via connected-component analysis. | |
| void | segment_sort_reading_order (SegmentResult *res) |
| Sort a SegmentResult's cells in reading order (top-to-bottom, left-to-right). | |
| void | segment_result_free (SegmentResult *res) |
| Free a SegmentResult returned by segment_image(). | |
Letter segmentation: detect crossword grid and extract letter cells.
Pipeline:
Alternatively, for images with clearly separated letter blobs, the connected-component analysis path extracts letter regions directly.
| int segment_connected_components | ( | const unsigned char * | pixels, |
| int | width, | ||
| int | height, | ||
| SegmentResult * | out ) |
Extract letter bounding boxes via connected-component analysis.
Uses an iterative flood-fill (queue-based, no recursion) to group connected black pixels into components. Components whose size and aspect ratio fall within the expected range for a letter are kept.
| pixels | Grayscale pixel array (0=black, 255=white), row-major. |
| width | Image width. |
| height | Image height. |
| out | Pre-allocated SegmentResult to fill. |


| int segment_detect_grid | ( | const unsigned char * | pixels, |
| int | width, | ||
| int | height, | ||
| float | min_span, | ||
| SegmentResult * | out ) |
Detect grid lines and infer cell geometry.
Finds horizontal and vertical runs of dark pixels spanning at least min_span proportion of the image dimension to identify grid lines. Returns regular grid cell positions if a consistent grid is detected.
| pixels | Grayscale pixel array (0=black, 255=white), row-major. |
| width | Image width. |
| height | Image height. |
| min_span | Minimum fraction of dimension a line must span [0, 1]. |
| out | Pre-allocated SegmentResult to fill. |
out filled, 0 if no grid was found.
| SegmentResult * segment_image | ( | const unsigned char * | pixels, |
| int | width, | ||
| int | height ) |
Segment a binarised image into letter cell bounding boxes.
Tries two strategies in order:
The returned SegmentResult::cells array is ordered left-to-right, top-to-bottom.
| pixels | Flat grayscale pixel array (1 byte/pixel, 0=black, 255=white), row-major, width × height bytes. |
| width | Image width in pixels. |
| height | Image height in pixels. |


| void segment_result_free | ( | SegmentResult * | res | ) |
Free a SegmentResult returned by segment_image().
| res | Result to free. No-op if NULL. |

| void segment_sort_reading_order | ( | SegmentResult * | res | ) |
Sort a SegmentResult's cells in reading order (top-to-bottom, left-to-right).
Cells are grouped into rows based on vertical overlap, then sorted left-to-right within each row.
| res | SegmentResult to sort in-place. |

