0

I want to call a function to compare all of the segments that I calculate in my code and know how many polygons there are in my view, made up of straight lines, which consist of 3, 4 or more segments that form a closed path, or alternatively i would like to know how many pairs of straight segments form an angle (thus have a common point):

           vector<Vec4i> lines;
       HoughLinesP(dst, lines, 1, CV_PI/180, 80, 50, 10 );
       for( size_t i = 0; i < lines.size(); i++ )
           {
           Vec4i l = lines[i];
           double x = l[0]-l[2];
           double y = l[1]-l[3];
           double dist = pow(x,2) + pow(y,2);
           dist= sqrt(dist);
           segments.push_back(round(dist));
           line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
           }

alternatvely, trying to simplify, how can i calculate the number of intersections between segments?

  • The image you used to compute Hough would helpful – Miki Jun 01 '16 at 16:48
  • basically I have to detect the geometric features in the images . I would like to be able to calculate for example the number of windows within an image , then I consider a window as a polygon composed of 4 segments that form a closed path – Ilario Piconese Jun 02 '16 at 12:20

1 Answers1

0

If I understand correctly, given a polygon you want to know how many vertices it has.

I think a nice option is to use cv::approxPolyDP, which will give you the minimum number of vertices needed to represent your polygon. According to the number of vertices, you can classify the polygons.

You can look at pyImageSerach blog for a good tutorial (in Python).

Elad Joseph
  • 2,998
  • 26
  • 41