The use of WarpPerspective projection correction in Opencv–perspective transformation

Method 1: In the current work, it is often necessary to use a mobile phone to take some pictures of monitors, or other documents or TVs as material and write them in a report to the leader or guests. The image requirements are more stringent, but sometimes my hands are shaking. After I took a picture and went back to write a report, I found that: wtf, what tm I shot at that time, and I can’t rearrange it. At this time, I can actually use the WarpPerspective projection transformation in [opencv to correct the image.]

Method 2: The other one is slightly more demanding for users, and there is a target terrain rectangle object function in the mobile phone.
Basic knowledge This blogger introduced in detail and complete: /guduruyu/article/details/72518340

The following example demonstrates

/*The following code only shows the transformation part, where ImageIn is the input image and ImageOut is the output image*/ 
//The four points before transformation 
var srcPoints = new Point2f[] {
     new Point2f( 5 , 648 ),
     new Point2f( 751 , 643 ),
     new Point2f( 184 , 280 ),
     new Point2f( 589 , 272 ),
};
//The transformed four points 
var dstPoints = new Point2f[] {
     new Point2f( 0 , 703 ),
     new Point2f( 524 , 703 ),
     new Point2f( 0 , 0 ),
     new Point2f( 524 , 0 ),
};
//According to the coordinates of the four points before and after the transformation, get the transformation matrix
Mat mm = Cv2.GetPerspectiveTransform(srcPoints, dstPoints); 
//Perspective transformation 
Cv2.WarpPerspective(ImageIn, ImageOut, mm, GrayImage.Size());

The following is the output result:
before transformation: the red point is the point I selected, after transformation: the red point is the original transformed point

Leave a Comment

Your email address will not be published. Required fields are marked *