私は Opencv に凸性欠陥のある輪郭 (赤のもの) があり、その輪郭を 2 つの部分に切り取り、その点を水平に横断したいのですが、とにかくそれを行う必要があるので、輪郭を黄色でマークしますか? 問題を説明する画像
1 に答える
That's an interesting question. There are some solutions based on how the concavity points are distributed in your image.
1) If such points does not occur at the bottom of the contour (like your simple example). Then here is a pseudo-code.
- Find convex hull C of the image I.
- Subtract I from C, that will give you the concavity areas (like the black triangle between two white triangles in your example).
- The point with the minimum y value in that area gives you the horizontal line to cut.
2) If such points can occur anywhere, you need a more intelligent algorithm which has cut lines that are not constrained by only being horizontal (because the min-y point of that difference will be the min-y of the image). You can find the "inner-most" corner points, and connect them to each other. You can recursively cut the remainder in y-,x+,y+,x- directions. It really depends on the specs of your input.