---
title: "Read rotated or skewed scans in C#"
url: https://recursiveai.org/oneocr/cookbook/ocr-rotated-and-skewed-page/
description: "Run OCR on sideways and tilted scans in C#. Detect the page turn, straighten text lines, and get word boxes in the original image’s coordinates."
version: "1.0.0"
---

# Read rotated or skewed scans in C#

**OneOcr** is a free, open-source OCR library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneOcr) · [GitHub](https://github.com/recursive-ai-oss/oneocr-csharp) · [Docs](https://recursiveai.org/oneocr/docs/) · [Download example (.zip)](https://recursiveai.org/oneocr/cookbook/ocr-rotated-and-skewed-page/ocr-rotated-and-skewed-page.zip)

OneOcr reads sideways scans and straightens tilted text lines before recognition.

```shell
dotnet add package RecursiveAI.OneOcr
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneOcr;

var engine = OcrEngine.LoadBundled();
var page = engine
    .OcrPages("turned.png").Single();
Console.WriteLine(page.ToText());
```

Unzip [the example](https://recursiveai.org/oneocr/cookbook/ocr-rotated-and-skewed-page/ocr-rotated-and-skewed-page.zip), then `dotnet run`.

`turned.png` is a sideways train note in the download. The snippet prints its text upright:

```text
Morning train to the coast
Meet at the station
Bring a map and water
Return before sunset
```

## The full program

The download has three generated PNGs with those same four lines: `turned.png` (90° clockwise), `tilted.png` (8° clockwise), and `steep32.png` (32° clockwise). The program checks the text, the input dimensions, and the first word’s position. On the sideways sample, “Morning” is near the **right** edge of the input, not the top left of a new upright image.

```csharp
using System.Globalization;
using OneOcr;

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
var engine = OcrEngine.LoadBundled();
var samples = new[]
{
    (File: "turned.png", Width: 275, Height: 560, Turn: 90, Skew: 0, Searched: false),
    (File: "tilted.png", Width: 594, Height: 351, Turn: 0, Skew: 8, Searched: false),
    (File: "steep32.png", Width: 622, Height: 531, Turn: 0, Skew: 20, Searched: true)
};
const string expected = "Morning train to the coast\nMeet at the station\nBring a map and water\nReturn before sunset";
foreach (var sample in samples)
{
    var page = engine.OcrPages(sample.File).Single();
    var text = page.ToText().ReplaceLineEndings("\n").Trim();
    var word = page.Words.First();
    bool searched = page.Diagnostics.Any(d => d.Code == OcrDiagnosticCodes.AngleSearched);
    if (text != expected || page.Orientation != sample.Turn ||
        Math.Abs(page.SkewDegrees - sample.Skew) > 0.2 || searched != sample.Searched ||
        page.Width != sample.Width || page.Height != sample.Height || word.Quad is null ||
        word.Box.Left < 0 || word.Box.Top < 0 ||
        word.Box.Right > sample.Width || word.Box.Bottom > sample.Height ||
        (sample.Turn == 90 && word.Box.Left < sample.Width / 2))
        throw new InvalidOperationException($"Unexpected OCR result for {sample.File}.");

    Console.WriteLine($"{sample.File}: turn {page.Orientation}°, skew {page.SkewDegrees:F1}°");
    Console.WriteLine(text);
    Console.WriteLine($"{word.Text} at ({word.Box.Left:F0}, {word.Box.Top:F0}) on {page.Width}×{page.Height}; quad: yes");
    Console.WriteLine($"Angle-search diagnostic: {searched}");
}
```

`dotnet run` prints:

```text
turned.png: turn 90°, skew 0.0°
Morning train to the coast
Meet at the station
Bring a map and water
Return before sunset
Morning at (211, 40) on 275×560; quad: yes
Angle-search diagnostic: False
tilted.png: turn 0°, skew 8.0°
Morning train to the coast
Meet at the station
Bring a map and water
Return before sunset
Morning at (70, 37) on 594×351; quad: yes
Angle-search diagnostic: False
steep32.png: turn 0°, skew 20.0°
Morning train to the coast
Meet at the station
Bring a map and water
Return before sunset
Morning at (146, 48) on 622×531; quad: yes
Angle-search diagnostic: True
```

For the 32° sample, `skew 20.0°` is the [winning reading’s reported skew](#how-do-i-deskew-a-tilted-image-for-ocr), not the image’s actual tilt.

If the page has no clear text direction, orientation detection reads it as given. Check the returned text before using it as a transcript.

## Variations

**Turn off the extra angle search** to compare with the first reading. Replace the `OcrPages` call at the top with these lines; `DetectOrientation` and `Deskew` stay on.

```csharp
var options = new OcrOptions { SearchAngle = false };
var page = engine.OcrPages("steep32.png", options).Single();
Console.WriteLine(page.SkewDegrees.ToString("F1",
    System.Globalization.CultureInfo.InvariantCulture));
```

On `steep32.png` this reports `12.0` instead of `20.0`.

## Related recipes

- [Extract text from an image](https://recursiveai.org/oneocr/cookbook/extract-text-from-image/)
- [Read character bounding boxes](https://recursiveai.org/oneocr/cookbook/read-character-level-ocr-boxes/)

## The short answer

Call `OcrPages(path)` to read a rotated or skewed image in C#. `DetectOrientation`, `Deskew`, and `SearchAngle` are on by default. Read the result with `page.ToText()`. If you’re highlighting matches on the scan, use the word boxes or corner coordinates from the same result. You don’t need to rotate those coordinates back yourself.

## How do I correct the orientation of a scanned document for OCR?

Orientation detection chooses among upright, sideways, and upside down: 0°, 90°, 180°, and 270°. `OcrPage.Orientation` tells you how far the content was turned **clockwise** from upright. On `turned.png` it’s 90°, meaning the tops of the lines point right. It isn’t an instruction to turn the image another 90°.

The correction is for reading. The OCR result doesn’t save a new image. In the sideways sample, `Width` and `Height` still describe the 275 × 560 input. `Box` is a rectangle with horizontal and vertical sides around the word. `Quad` gives the four corners in the text’s own order: top left, top right, bottom right, bottom left. Use the rectangle for a rough highlight, or the four corners if the highlight should follow the tilted text. See the [page geometry docs](https://recursiveai.org/oneocr/docs/page-json/).

## How do I deskew a tilted image for OCR?

Deskew corrects a smaller tilt, such as a page that went into a scanner at an angle. It straightens text lines tilted by up to about 15°; tilts under about 0.3° are left alone. `SkewDegrees` reports the tilt removed before reading, positive for lines descending to the right. That’s why the 8° image can have `Orientation` of 0° and still be straightened.

When the first reading is weak, `SearchAngle` can try other whole-page angles and keep a reading with more confidently read text. The diagnostic `OcrDiagnosticCodes.AngleSearched` marks when a different reading won; its absence doesn’t establish that no angles were tried. In the steep sample, the winning reported skew was 20° even though the image was made with a 32° turn. Treat this as a reading choice, not a measurement of the camera angle or a promise that every image at 32° works. See [how OneOcr finds and maps angles](https://recursiveai.org/oneocr/docs/orientation/).
