Home openCV perspective transformation doesn't work as expected
Reply: 0

openCV perspective transformation doesn't work as expected

user1107 Published in August 16, 2018, 6:15 am

I have an image with a text. This is the image:

What I'm trying to do is to straighten the text, using perspective transformation.

The red dots in the corners are the detected boundaries.

This is more or less my code (hard-coded, for simplicity):

bor=cv2.boundingRect(old_pts) #bounding_rect
ul=[bor[0],      bor[1]]       #upper left
ur=[bor[0],      bor[1]+bor[3]] #upper right
br=[bor[0]+bor[2],bor[1]+bor[3]] #bottom right
bl=[bor[0]+bor[2],bor[1]]       #bottom left

new_pts=np.float32([ul,ur,br,bl]) #new pts=[[2,0],[2,1122],[1390,1122],[1390,0]]

M = cv2.getPerspectiveTransform(old_pts,new_pts)
transformed_img = cv2.warpPerspective(new_img,M,(bor[3],bor[2])) #bor[3] and bor[4] are the bounding rect height&width. 


Now, the result I'm getting is this:

Why am I not getting a nice, straightened rectangle??

Any help will be appreciated!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302048 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO