4.2.3 Poly Approximate Process

Up to now, I have finished the process of contours, the next step, ‘poly approximate process’, is crucial to analysis the shape from a contour. This method is used to analysis polygons, and the basic idea is to line the curves and decrease the number of points of contours, so that people could get a rough concept of a shape. The picture 4.2.10 shows the comparison of an image before and after approxPolyDP when user click the button ’PolyProcess’ as shown in figure 4.1.2. Inside of this method Code Segment A, there are two vectors, original points set (c) and result points set (result). Peri is a parameter which is used to calculate the length of contours, and there is an important boolean parameter which indicates if the contour is closed (true) or opened (false). In this case, I set this parameter as true.

void Controller::approx_polygon(vector<Point> c, vector<Point> &result)
{
    double peri;
    peri=arcLength(c,true);
    approxPolyDP(c,result,peri*0.025,true);
}
}
Code Segment A: Polygon Approximation
Figure 4.2.10 (a): Original Image
Figure 4.2.10 (b): Polyprocess Result