openCV cvContourArea [英] openCV cvContourArea

查看:150
本文介绍了openCV cvContourArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cvFindContours,这显然是可行的方法.我遇到了最大的问题.有一个调用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;
}

我尝试用轮廓替换存储(在cvContourArea中),但是无论如何,都会出现相同的错误:

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

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

我用谷歌搜索,几乎找不到cvContourArea的示例,该示例需要3个参数..好像它最近被更改了. !

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!

推荐答案

在以下语句中尝试将&storage更改为current_contour.

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));

这篇关于openCV cvContourArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆