Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract simple geometric forms from contours in opencv

I have a Mat contours and I have approximated each contour with approxPolyDP. What I want to do now is detecting forms like rectangle, triangle, circle. And e.g. redraw them in a different color or using canvas etc.

Is there a way of making use of the contours? How can I access points in Mat contours and simplify them a little further (removing deformations or if two significant points are so close together, that I can safely remove one of them)?

I am developing in Java (Android), so not every C/C++ method/type is available to me (or a JNI-call would be a waste).

like image 853
sschrass Avatar asked Nov 13 '22 08:11

sschrass


1 Answers

The contours are returned as vector > contours. You can access them easily in C++ by doing something like:

vector<vector<Point> > contours;
findContours(..,contours,...);
contours.at(0).at(0) //first point of first contour

If you are accessing them using a Mat then you will need to test what arrangement is produced. It should be very easy, though, although having said that, JNI and android opencv is a pain.

like image 172
alistair Avatar answered Nov 16 '22 03:11

alistair