Rotation Correction

This example shows how to use the Hough Transform and Polyfit blocks to horizontally align text rotating in a video sequence. The techniques illustrated by this example can be used in video stabilization and optical character recognition (OCR).

Example Model

The following figure shows the Rotation Correction example model:

Text Alignment Using Hough Transform Subsystem

The morphological operators in the Smudge text subsystem blur the letters to create a binary image with two distinct lines. You can see the result of this process in the Smudged Video window.

By transforming the binary image into the Hough parameter space, the example determines the theta and rho values of the lines created by the Smudge text subsystem. Once the theta values of the text lines are known, the example uses the Rotate block to eliminate the large angular variations.

Post-Processing: Text Alignment Using Polynomial Fit Subsystem

The example uses the Polyfit block, in the slope correction subsystem, and the Rotate block to eliminate small angular variations in the text. The Polyfit block fits a straight line to the smudged text. Then the slope correction subsystem calculates the slope of the line and its angle of inclination. The Rotate block uses this angle to correct for the small rotations.

Rotation Correction Results

The Input Video window shows the original video. The Smudged video window shows the result of blurring the letters to create a binary image with two distinct lines. In the Hough Matrix window, the x- and y-coordinates of the two dominant yellow dots correspond to the theta and rho values of the text lines, respectively. The Corrected video window shows the result of the rotation correction process.

Available Example Versions

Windows® only: viphough_win.slxviphough_win.slx

Platform independent: viphough_all.slxviphough_all.slx

Windows-only example models might contain compressed multimedia files or To Video Display blocks, both of which are only supported on Windows platforms. The To Video Display block supports code generation, and its performance is optimized for Windows.

Was this topic helpful?