In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "C++ how to use OpenCV to achieve perspective transformation function", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how C++ uses OpenCV to achieve perspective transformation.
Preface
When we take a picture, we can't guarantee that the picture is taken vertically at the bottom, so when we get the image, it will prevent us from extracting the correct image, so we need to use perspective transformation here. Today we will try the perspective transformation in OpenCV.
Realize the effect
The above picture is our direct shooting of the mobile phone, we can find that the image is not taken vertically above.
The above is the new picture effect generated by the perspective transformation.
API function
GetPerspectiveTransform
Calculation of transmission transformation from four pairs of points
CvMat* cvGetPerspectiveTransform (const CvPoint2D32f* src, const CvPoint2D32f* dst, CvMat*map_matrix)
Detailed description of parameters:
Src enters the quadrilateral vertex coordinates of the image.
Dst outputs the corresponding quadrilateral vertex coordinates of the image.
Map_matrix A pointer to the 3 × 3 output matrix.
The function cvGetPerspectiveTransform calculates the transmission transformation matrix that satisfies the following relations:
Here, dst (I) = (xonomiMagneyfanti), src (I) = (xi,yi), I = 0.. 3.
WarpPerspective function
Main function: perspective transformation of the image
The calling form of the function:
Void warpPerspective (InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar ())
Detailed description of parameters:
InputArray src: imported ima
OutputArray dst: exported ima
InputArray M: the Matrix of Perspective Transformation
Size dsize: the size of the output image
Int flags=INTER_LINEAR: interpolation method of output Image
Code demonstration
Let's create a new project named opencv--toushi, follow the configuration properties (VS2017 configure OpenCV generic properties), and then write # include and main methods in the source file.
Define the coordinates of the perspective transformation
The definition of the points in the src_corners above is based on the points set by ourselves on our original diagram. Later we will find an opportunity to use the program to obtain these points.
Dst_corners is the point that we want to generate after the matrix change.
The order of defining four points should be obtained clockwise, as shown in the following figure
Get the perspective transformation matrix and display the last image
The resulting effect
The picture on the right is the image effect we finally get through perspective transformation. On the basis of this image, it is very simple for us to do some feature extraction.
At this point, I believe that everyone on the "C++ how to use OpenCV to achieve perspective transformation function" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.