0

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: enter image description here

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.

nvcnvn
  • 4,991
  • 8
  • 49
  • 77

1 Answers1

2

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.

Boyko Perfanov
  • 3,007
  • 18
  • 34