Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

contourArea() uses Green formula (http://en.wikipedia.org/wiki/Green's_theorem) to compute the area, therefore its complexity is O(contour_number_of_vertices). Counting non-zero pixels in the ROI is O(roi_width*roi_height) algorithm, i.e. much slower. Note, however, that because of finite, and quite low, resolution of the raster grid, the two algorithms will give noticeably different results. For large and square-like contours the error will be minimal. For small and/or oblong contours the error can be quite large.