getPerspectiveTransform confirms the principle analysis of the perspective transformation matrix through 4 pairs of points

☞ ░LaoYuanPython blog post directory: https://blog.csdn.net/LaoYuanPython

I. Introduction

The essence of image perspective transformation (Perspective Transformation) is to project an image from one geometric plane to another. Perspective transformation ensures that the points of the same straight line are still on the same straight line, but are no longer guaranteed to be parallel. Because this is a two-dimensional image that undergoes a three-dimensional transformation, and then is mapped to another two-dimensional space, the two-dimensional space of the two-dimensional image is different from the two-dimensional space after the mapping, if the same is the affine transformation.

Similar to the " https://blog.csdn.net/LaoYuanPython/article/details/113788380 Image Affine Transformation Principle 3: Affine Transformation Type and Transformation Matrix Detailed Explanation " introduced the affine matrix of affine transformation, the perspective transformation is also based on Based on the matrix operation, the pixel correspondence between the old and the new image can be quickly found through the matrix operation.

The perspective transformation is described by the following homogeneous coordinate formula: the
Insert picture description here
above 3rd order square matrix is ​​the perspective transformation matrix, this matrix is ​​a homography matrix, after the matrix is ​​determined, the mapping relationship between the old and the new image can be confirmed, and in OpenCV -In Python, the function getPerspectiveTransform can get the perspective transformation matrix through four pairs of points.

2. Analysis

The homogeneous coordinate formula of perspective transformation also corresponds to the linear equation system:
Insert picture description here
convert homogeneous coordinates (X,Y,Z) to (x',y',1)(for those interested in the explanation of homogeneous coordinates, please refer to the old monkey paid column " https://blog.csdn.net/LaoYuanPython /article/details/113743213 Principle of Image Affine Transformation 1: Homogeneous coordinate ins and outs "), you can know:
Insert picture description here
from the above formula, you can know that to confirm the 9 elements of a perspective transformation matrix, you must pass a certain number of known The coordinates of the source image (x, y) and the coordinates (x', y') of the result image are used to solve the values ​​of these 9 elements. So how many points can solve these 9 element values? This number is 4 pairs, which are 4 points where any three points in the source image are not on a straight line and 4 points corresponding to the corresponding positions of the target image. Why are there 4 pairs of points? This is because:

  1. 4 points correspond to 4 sets of (x, y), (x', y') values, put them into the above formula, you can get 8 equations;
  2. Since the above formula is based on homogeneous coordinates, the following two formulas are equivalent
    Insert picture description here
    to
    Insert picture description here
    and According to the knowledge of matrix multiplication and matrix number multiplication, there are:
    Insert picture description here

Set k=1/m 33 , then k×m 33 =1, and set k×m ij = M ij , then the final perspective matrix has only 8 variables.

Three, summary

This article analyzes the principle of getPerspectiveTransform in OpenCV-Python to confirm the perspective transformation matrix through 4 pairs of points, which will help everyone understand the knowledge of perspective transformation.

Four, reference knowledge

For more image processing introduction, please refer to the column " OpenCV-Python graphics and image processing https://blog.csdn.net/laoyuanpython/category_9979286.html " and " https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV -Python Beginners Difficult Questions Collection " related articles.

For more basic mathematical knowledge of image processing, please refer to the column " Artificial Intelligence Mathematical Foundation https://blog.csdn.net/laoyuanpython/category_10382948.html "

Blogging is not easy, please support:

If you have gained something from reading this article, please like, comment, bookmark, thank you for your support!

Reference materials :

  1. [Python image processing] 6. Image zoom, image rotation, image flip and image translation

Paid column about the old ape

  1. The paid column " https://blog.csdn.net/laoyuanpython/category_9607725.html Using PyQt to Develop Graphical Interface Python Applications" specifically introduces the basic tutorials for Python-based PyQt graphical interface development. The corresponding article directory is " https://blog.csdn .net/LaoYuanPython/article/details/107580932 Use PyQt to develop a graphical interface Python application column directory ";
  2. The paid column " https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy audio and video development column ) details the related methods of moviepy audio and video editing and synthesis processing and the use of related methods to process related editing and synthesis scenes, corresponding to the article The directory is " https://blog.csdn.net/LaoYuanPython/article/details/107574583 moviepy audio and video development column article directory ";
  3. The paid column " https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python Difficult Questions for Beginners " is " https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python graphics and image processing "The companion column" is an integration of the author’s personal perceptions of some of the problems encountered in the learning of OpenCV-Python graphics and image processing. The relevant information is basically the result of repeated research by the old ape, which helps OpenCV-Python beginners to more in-depth To understand OpenCV, the corresponding article directory is " https://blog.csdn.net/LaoYuanPython/article/details/109713407 OpenCV-Python Beginners Difficult Question Collection Column Directory "
  4. The paid column " https://blog.csdn.net/laoyuanpython/category_10762553.html Introduction to Python Crawler" introduces the content of crawler development from the perspective of an Internet front-end developer, including the basic knowledge of crawler introduction, and crawling Take CSDN article information, blogger information, like articles, comments and other actual content.

The first two columns are suitable for novice readers who have a certain Python foundation but no relevant knowledge. The third column, please combine " https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python graphics and image processing " Learning to use.

For those who lack Python foundation, you can learn Python from scratch through Lao Yuan’s free column " https://blog.csdn.net/laoyuanpython/category_9831699.html column: Python basic tutorial directory ).

If you are interested and willing to support the readers of Old Ape, welcome to buy paid columns.

Learn Python from the old ape!

☞ ░Go to LaoYuanPython blog post directory https://blog.csdn.net/LaoYuanPython

Guess you like

Origin blog.csdn.net/LaoYuanPython/article/details/114108429