python opencv get rotated scaled clipped original matching the template

168 Views Asked by At

I am taking repeatedly (1 minute) an image of a device control panel that uses led's to show it's current status (current).

I have created a template .jpg of the panel section showing the led section in reference form (vertically aligned, clipped).

I use a flann matcher and cv.drawMatches(..) to draw the lines between the current and the template image.
This shows a nice and complete relation (in my case green lines) between the original and template key points.

In order to evaluate the current devices settings (lighted led's) I need a scaled, rotated, clipped section of the current image that matches the template (right top).

enter image description here

Could not find any examples how to apply the needed transition/clipping back to the current jpg to start the search for currently active led's.

1

There are 1 best solutions below

0
juerg On

after more reading I ended up with this solution after finding the source and destination points of the 2 images:

M, mask = cv.findHomography(src_pts, dst_pts, cv.RANSAC,5.0)
warped = cv.warpPerspective(img1, M, (w1, h1), flags=cv.INTER_LINEAR)
cropped = warped[0:h2, 0:w2]

This results in the rotated scaled section of the current image in the size of my reference image.