Skip to content

contourArea

geometryfunctionOpenCV 5.0.0
import { contourArea } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTScontour, oriented
FUNCTIONcontourArea
RETURN TYPEnumber
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Calculates a contour area.

The function computes a contour area. Similarly to moments , the area is computed using the Green formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using #drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong results for contours with self-intersections.

Example:

   vector<Point> contour;
   contour.push_back(Point2f(0, 0));
   contour.push_back(Point2f(10, 0));
   contour.push_back(Point2f(10, 10));
   contour.push_back(Point2f(5, 4));

   double area0 = contourArea(contour);
   vector<Point> approx;
   approxPolyDP(contour, approx, 5, true);
   double area1 = contourArea(approx);

   cout << "area0 =" << area0 << endl <<
           "area1 =" << area1 << endl <<
           "approx poly vertices" << approx.size() << endl;
contourArea(contour: Mat, oriented: boolean): number;
2 available overloads
contourArea(contour: Mat): number;
contourArea(contour: Mat, oriented: boolean): number;
contour

Input vector of 2D points (contour vertices), stored in std::vector or Mat.

oriented

Oriented area flag. If it is true, the function returns a signed area value, depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can determine orientation of a contour by taking the sign of an area. By default, the parameter is false, which means that the absolute value is returned.

Returns

The number result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.