pointPolygonTest in OpenCV
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 );`
The drawing image is below
This is a basic debugging task: 1) how does your contour look like? (e.g. use drawContours and show the image) 2) What output do you get right now?
I see some cout in your code. As suggested by @FooBar, can you post the output you get?
I used drawContours and there is a result image in my question text. All calculated distance are negative now.