Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Opencv_contourArea

$
0
0
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 hierarchy; vector> 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 all_pixels; // output, locations of non-zero pixels cv::findNonZero(mask, all_pixels); vector 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; }

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>