Perspective Correction
Perspective correction (projective correction) is image processing that converts the trapezoidal distortion produced when a camera photographs an object at an angle into the square state seen from the front. Using a projective transformation matrix, it maps the 4 vertices of the distorted quadrilateral to the 4 vertices of a square.
Perspective correction is indispensable in decoding QR codes. Users rarely scan a QR code from directly in front, and almost always point the camera at an oblique angle. In situations such as looking down from above at a QR code placed on a table, or photographing a QR code stuck on a wall from the side, the QR code is captured distorted into a trapezoid or a parallelogram.
The scanner calculates the distortion of the QR code from the positional relationship of the 3 finder patterns. It analyzes how the finder patterns, which should be square, have been deformed, and applies the inverse transformation to return them to a square. Binarization and module determination are then performed on this corrected image.
The accuracy of perspective correction depends on the accuracy with which the finder patterns are detected. If part of a finder pattern is hidden, or the image is taken from an extreme angle (almost directly from the side), the correction becomes inaccurate and reading fails. When placing a QR code, it is recommended to choose a position where users can scan it from an angle of 30 degrees or more.