openCV cvContourArea

I’m trying to use cvFindContours, which definitely seems like the way to go. I’m having a problem with getting the largest one. There is a function call cvContourArea, which suppose to get the area of a contour in a sequence. I’m having trouble with it.

int conNum = cvFindContours(outerbox, storage, &contours, sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_NONE,cvPoint(0, 0));
CvSeq* current_contour = contours;
double largestArea = 0;
CvSeq* largest_contour = NULL;

while (current_contour != NULL){
    double area = fabs(cvContourArea(&storage,CV_WHOLE_SEQ, false));       
    if(area > largestArea){
        largestArea = area;
        largest_contour = current_contour;
    current_contour = current_contour->h_next;

I tried replacing storage (in the cvContourArea) with contours, but same error keeps coming up no matter what:

  • Sprite Kit bodyAtPoint and bodyInRect return incorrect values?
  • Iphone - Check if a group name already exist in addressbook
  • iOS 6 Saving/Restoring app state feature
  • swift spritekit Facebook share button
  • Swift - How to save memory using AlamofireImage/ImageShack?
  • Sphere in OpenGL es 2.0 iOS
  • OpenCV Error: Bad argument (Input array is not a valid matrix) in cvPointSeqFromMat, file /Volumes/ramdisk/opencv/OpenCV-2.2.0/modules/imgproc/src/utils.cpp, line 53

    I googled and could hardly find example of cvContourArea that takes 3 arguments.. as if it’s changed recently.. I want to loop thru the found contours and find the biggest one and after that draw it using the cvDrawContours method.. Thanks!

    Solutions Collect From Internet About “openCV cvContourArea”

    Try to change &storage to current_contour in the following statement.


    double area = fabs(cvContourArea(&storage,CV_WHOLE_SEQ, false)); 


    double area = fabs(cvContourArea(current_contour,CV_WHOLE_SEQ, 0));