OpenCV C++/Obj-C: Detecting a sheet of paper / Square Detection

前端 未结 6 1168
离开以前
离开以前 2020-11-22 01:47

I successfully implemented the OpenCV square-detection example in my test application, but now need to filter the output, because it\'s quite messy - or is my code wrong?

6条回答
  •  执念已碎
    2020-11-22 02:31

    What you need is a quadrangle instead of a rotated rectangle. RotatedRect will give you incorrect results. Also you will need a perspective projection.

    Basicly what must been done is:

    • Loop through all polygon segments and connect those which are almost equel.
    • Sort them so you have the 4 most largest line segments.
    • Intersect those lines and you have the 4 most likely corner points.
    • Transform the matrix over the perspective gathered from the corner points and the aspect ratio of the known object.

    I implemented a class Quadrangle which takes care of contour to quadrangle conversion and will also transform it over the right perspective.

    See a working implementation here: Java OpenCV deskewing a contour

提交回复
热议问题