Recognize open and closed shapes opencv

前端 未结 4 1003
终归单人心
终归单人心 2020-12-04 17:17

how to detect open and closed shapes in opencv.

\"enter

These are simple sampl

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 17:37

    While correct for the problem posed, @Haris helpful answer should not be taken as a general solution for identifying closed contours using findContours().

    One reason is that a filled object will have no internal contour and so would return hierarchy[i][2] = -1, meaning this test on its own would wrongly label such contours as 'open'.

    The contour of a filled object should have no child or parent in the contour hierarchy, i.e. be at top level. So to detect for closed contours of filled objects would at least require an additional test: if(hierarchy[i][2] < 0 && hierarchy[i][3] < 0).

    I think @Haris answer may have made this point obliquely but I thought it worth clarifying for people, like myself, who are learning how to use opencv.

提交回复
热议问题