简体   繁体   中英

How to find the transformation matrix for warpPerspective to bring the rotated image to the normalized position?

I need to process some of the information obtained from the scanner. The problem is the image I get occasionally rotated. I decided to add a few special objects on the photo to be able to use with technical Features2D + Homography to find that object. I think after finding special objects I could rotate the image back to its original position (with warpPerspective?). Here is an example:
The rotated image, I know that under the black-box there is some text, I need that area for OCR function: 在此输入图像描述

I'm stuck after finding the black-box.I think I'll use the warpPerspective to rotate it, but how to find out the 3x3 transformation matrix?
Thanks.

Use the FindHomography method.

Feed it the 4 source points. For the destination points, you will have to do some math as in where the 4 points should lay down in the destination image. A simple, straightforward operation to start with would be:

(from top-left going clockwise)
A' = (A.x, A.y)
B' = (A.x + length, A.y)
C' = (A.x + length, A.y + width)
D' = (A.x, A.y + width)

Map (A,B,C,D) to (A', B', C', D') using the FindHomography().

Where width and length are those of the identified rectangle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM