Reputation: 1030
I've been spending a few evenings tinkering with OpenCV. I'm working on a small project that does some analysis on content within a page. I'd like to do a perspective transform of the page to line and fit the entire screen first. However, I can't depend that people will be holding the paper on a different coloured background, or back enough to fit the entire page boundaries.
So I thought of adding markers on opposite corners of the page to track, get their positions, and do a warp transform with them. Here is the sample image of the corner-markers I am trying to detect:
What is the best approach for this? I'm mainly looking for someone to point me in the right direction.
Upvotes: 1
Views: 1179
Reputation: 21213
You can first get the first black pixel in the image and the last black pixel in the image after applying binary threshold to it. You will obtain 2 points that are diagonal to each other.
Using these two points you can obtain the other diagonal points
using img.shape
property.
Now you have 4 points, after which you can perform warp transform.
Upvotes: 0
Reputation: 11795
Cute idea! As others have noted, two points are not enough, but your markers define four lines, and those are enough.
If you can reliably detect edges on the line segments forming your markers, you can fit lines to them and then either directly compute the line homography (and then inverse-transpose it to convert it to a point homography), or intersect the lines in pairs to get four independent corners, and then compute the point homography on them.
Some experimentation may be needed to reliably detect your markers. You may want to consider using template matching.
Upvotes: 1