Perspective detection with OpenCv
If I want to detect perspective distorted objects (e.g rectangles) and calculate the correction transformation, what would be a good method?
For example, I have a lot of ph开发者_JAVA百科otos of papers lying on a flat surface (the photos are shot from an angle), and I want to correct the perspective and crop them.
I am thinking of using the OpenCv Python bindings to whip something up. I thought it would be a "standard problem" with lots of examples, but I failed to find any relevant info. Clues?
EDIT: I should add that I know it can be done by using some Web services, but I see this as a chance of doing something useful while learning OpenCv :)
You have to specify exactly what you mean with detecting the distortion. I assume you want to detect the corners of such a paper (or your table/flat surface) and make it axis-parallel to your display. This can be done using cvFindHomography
and cvWarpPerspective
. I have written some example code a while ago for python, note that those are still the old bindings (shouldn't take long to update to opencv 2.0 though): http://ioctl.eu/blog/2009/05/13/opencv_homography
The other thing you obviously have to do is detecting the corners. In my sample code, the user is required to click four corners using the mouse. In your case, it is hard to tell because I need an example. OpenCV offers several means to detect corners (see Harris), also in the examples there should be code on how to find rectangles. If you could be more specific, I might be of greater assistence.
UPDATE This might be interesting for you as well: I've just heard a talk on manipulating perspective distortion in images (to e.g. increase the foreshortening). They require heavy user interaction, but optimize some grid with some constrains to maintain a smooth warping. Here is the acm link: http://portal.acm.org/citation.cfm?id=1778765.1778864 Maybe you can draw some ideas from that paper and the mentioned references, however I haven't read it myself (yet).
精彩评论