Sheet layout and alignment
Normalized canvas
alignImage first resizes the source image to width 1000 while preserving its aspect ratio. It converts the result to grayscale, applies a 5x5 Gaussian blur, applies adaptive Gaussian thresholding with block size 51 and constant 15, and performs a 5x5 rectangular morphological open.
It then searches external contours for four likely corner markers. A candidate must have:
- Area greater than
100and less than3000. - Width-to-height aspect ratio between
0.7and1.3. - Contour extent greater than
0.6.
The four selected points are ordered by coordinate sums and differences, then mapped to destination points (50,50), (750,50), (750,1150), and (50,1150). The perspective warp produces an 800x1200 image.
Fallback
If fewer than four candidate corners are found, the service logs a warning and resizes the original image directly to 800x1200. This fallback is not a configurable layout mode and does not establish accuracy for arbitrary sheet designs.
Fixed identity crops
After alignment, OCR receives two fixed regions:
- Name:
(x=150, y=100, width=300, height=50). - Class:
(x=500, y=100, width=150, height=50).
These coordinates assume the normalized 800x1200 canvas.