1 | initial version |
I guess that you want to find a rectangle that was deformed by a perspective transformation. Is this right? In this case I'd try to merge the short lines, find the four endpoints of the merged lines and use getPerspectiveTransformation to estimate the transformation. If you make a mistake during merging, the reprojection error of the transformation will be rather high so you can try to adjust your merging (maybe ignore some of the shorter lines or something similar) until you get a transformation with a good reprojection error. This approach is called RANSAC and could probably solve this problem.