After detecting the lines in an image using Hough lines, how can I use it to calculate the change in angle (rotation) of the lines of a reference image?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note to readers: This is a follow-up question, refer to these for background:
The process is similar to what I showed before. Below I am using the images from your previous question (since you provided only one, I created the other by rotating the first by 10 degrees).
We start by detecting the lines for the two images. We do this with the help of the Hough transform functions. This what it looks like applied to both images:
Next, we want to perform image registration using the line endpoints as control-points. First, we make sure the points correspond to each other in the two images. I do this by computing the convex hull using
convhullwhich automatically sorts them in counterclockwise-order (or is it in the opposite direction!). The numbers shown above indicate the order.Finally, we use the function
cp2tformto get the transformation matrix, which we use to align the images and extract the translation, rotation, and scaling.The following is the complete code:
And here’s the function that extract the lines endpoints:
with the result:
The rotation is recovered as almost 10 degrees (with some inevitable error), and scaling is effectively 1 (meaning there was no zooming). Note that there was a translation component in the above example, because rotation was not performed around the center of the cross sign).