Java – opencv with arbitrary contour transforms the shape into a rectangle
The short question is how to use OpenCV to convert the following shapes into rectangles?
Notes:
>Shape contours are not necessarily straight lines – they may be slightly curved. > The contents of the shape must be stretched, so the X and Y axes are the same
Long story: I try to correct the distortion of the image representing the paper, text, logo, etc. after the paper is folded 2 or 4 times, and make it almost completely rectangular
The input image is already in black and white format and has a corrected perspective So everything is fine, except that it has a black area around the twisted edge and the text is a little wavy
My idea is that the sequence should be like this:
>Locate the paper outline > calculate correction matrix to map the shape area to the appropriate rectangular area > transform the image using the calculation matrix
That is, we use imgproc Findcontours performs perspective correction, then finds the corner of the workbench, and then imgproc Getperspectivetransform, and finally use imgproc Correct the warpsperspective
But I can't find an algorithm suitable for this situation
Can anyone point out how to get it in image processing?
Solution
In this case, you want to nonlinear transform the image Traditionally, you will use a single conversion of the entire paper to make it rectangular This can be done using only corners For more complex corrections, such as lens distortion, you need to pick points on the page and assert that they should be coplanar to generate a transformation matrix Basically, you need to understand the geometry in the image to distort it Therefore, the geometry you need to find is the three-dimensional surface of the page
In order to find the highly nonlinear geometry of damaged paper, you can take multiple page images and triangulate them If you want to go this way, please pick up Hartley and zisserman's multi view geometry copy