c++algorithmopencvcurves

extract dots from curves


I have a black and white picture of curves and I want to extract minimum dots representing each curve. dots are connected by straight lines. this is an example of what I want:

enter image description here enter image description here

It is useful If I could know the precedence of dots especially in tied sections. I'm using c++ and opencv. What algorithms I should use for this problem?


Solution

  • OpenCV provides nice and simple function for this cv::approxPolyDP.

    void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
    

    A simple example:

    std::vector<cv::Point> curve;
    //fill curve
    std::vector<cv::Point> approximated_polyline;
    cv::approxPolyDP(Mat(curve), approximated_polyline, 3, false);