


How to Deskew Points Using Perspective Transformation and Affine Transforms?
Nov 21, 2024 am 01:15 AMPerspective Transformation for Deskewing
To achieve a deskewing effect on a set of points using perspective transformation, it's essential to understand the following:
Point Ordering:
The order of points matters in perspective transformation. To ensure accuracy, the order must be consistent in both the source and destination vectors.
Image Size:
If you want the resulting image to only contain the object of interest, set its width and height to match the resulting rectangle's dimensions.
Performance Considerations:
For affine transformations like rotate, resize, and deskew, it's more efficient to use the affine counterparts:
- getAffineTransform()
- warpAffine()
Affine Transform:
getAffineTransform() only requires three points and provides a 2x3 matrix, while warpAffine() performs the warping.
Resizing the Resulting Image:
To resize the resulting image to a different size than the input, use:
cv::Size size(box.boundingRect().width, box.boundingRect().height); cv::warpPerspective(src, dst, size, ... );
Example:
vector<Point> not_a_rect_shape; not_a_rect_shape.push_back(Point(408, 69)); not_a_rect_shape.push_back(Point(72, 2186)); not_a_rect_shape.push_back(Point(1584, 2426)); not_a_rect_shape.push_back(Point(1912, 291)); RotatedRect box = minAreaRect(cv::Mat(not_a_rect_shape)); Point2f pts[4]; box.points(pts); Point2f src_vertices[3]; src_vertices[0] = pts[0]; src_vertices[1] = pts[1]; src_vertices[2] = pts[3]; Point2f dst_vertices[3]; dst_vertices[0] = Point(0, 0); dst_vertices[1] = Point(box.boundingRect().width-1, 0); dst_vertices[2] = Point(0, box.boundingRect().height-1); Mat warpAffineMatrix = getAffineTransform(src_vertices, dst_vertices); cv::Size size(box.boundingRect().width, box.boundingRect().height); warpAffine(src, rotated, warpAffineMatrix, size, INTER_LINEAR, BORDER_CONSTANT);
The above is the detailed content of How to Deskew Points Using Perspective Transformation and Affine Transforms?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the types of values returned by c language functions? What determines the return value?

C language function format letter case conversion steps

What are the definitions and calling rules of c language functions and what are the

Where is the return value of the c language function stored in memory?

How does the C Standard Template Library (STL) work?

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently?
