0

I want to find center of palm. Firstly,I found contours and select max area contour. And I used pointPolygonTest. My code and result image are below, but I didn't find any point using pointPolygonTest. What is the problem?

double dist, maxdist = -1;
    Point center;
    for(int i = 0; i< drawing.cols; i += 10) {
        for(int j = 0; j< drawing.rows; j += 10) {

            dist = pointPolygonTest(contours[maxAreaIndex], Point(i,j),true);
            cout << "   dist " << dist << endl;
            if(dist > maxdist)
            {
                maxdist = dist;
                center = cv::Point(i,j);
            }
        }
    }
    cout << "maxdist = " << maxdist << endl;
    circle(drawing, center, maxdist, cv::Scalar(220,75,20),1,CV_AA);
    /// Show in a window
    namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
    imshow( "Contours", drawing );

enter image description here

  • Why are i,j in the range 1..10? – stark Oct 26 '14 at 15:30
  • When I used +1,it was too slow. –  Oct 26 '14 at 15:32
  • Should you pass contours rather than contours[maxAreaIndex] to pointPolygonTest? How is it defined? – stark Oct 26 '14 at 16:09
  • I used this definition vector > contours; And I calculated max area after findContours(...) function. int maxAreaIndex = 0; for( int i = 1; i< contours.size(); i++ ) { area = fabs(contourArea(contours[i])); if (area > max_area) { max_area = area; maxAreaIndex = i; } } –  Oct 26 '14 at 16:11

0 Answers0