HI,
When I calculate the area of via the contourArea function in binary image, I'm not getting the correct contour area. Below the snippet code, why the area is calculated incorrectly ? I have used a contour mask but it doesn't solve the problem.
vector<vec4i> hierarchy; vector<vector<point> > contours;
//findContours(bw, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
findContours(bw, contours, hierarchy, CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
Mat mask = Mat::zeros(bw.size(), CV_8UC1);
for (size_t i = 0; i < contours.size(); ++i)
{
drawContours(mask, contours, i, Scalar(255, 255, 255),
CV_FILLED, 8, hierarchy, 0, Point());
vector<Point> all_pixels; // output, locations of non-zero pixels
cv::findNonZero(mask, all_pixels);
vector<Point> all_pixels;
cv::findNonZero(mask, all_pixels);
int inside_phase = all_pixels.size() - contours.size();
// Calculate the area of each contour
double area = contourArea(contours[i], true);
cout << " Area#" << i <<": " << area << endl;
cout << " inside: " << inside_phase << endl;
}