Opencv FindContours功能

时间:2013-12-06 16:48:41

标签: c opencv

我尝试用opencv编写一个函数来检测轮廓并计算图像中对象的数量:

int casse (IplImage *img)
{

int nombre_objet=0;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = 0;

IplImage * Image_erode= cvCreateImage( cvGetSize(img),IPL_DEPTH_8U, img->nChannels);

%img is already a binary image:
cvErode(img,Image_erode,NULL,22);

cvFindContours( Image_erode, storage, &contours, sizeof(CvContour),CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );

nombre_objet=size.contours();

return nombre_objet;
}

我有这个错误:'size'未声明(首次使用此功能)

请帮助。

1 个答案:

答案 0 :(得分:0)

CvSeq是dynamic structure。它没有属性“大小”。它确实有一个属性“总”。也许这就是你要找的东西。

CvSeq¶

struct CvSeq

    Dynamically growing sequence.

    int flags

        sequence flags, including the sequence signature (CV_SEQ_MAGIC_VAL or 
        CV_SET_MAGIC_VAL), type of the elements and some other information about the sequence.

    int header_size

        size of the sequence header. It should be sizeof(CvSeq) at minimum. See CreateSeq().

    CvSeq* h_prev

    CvSeq* h_next

    CvSeq* v_prev

    CvSeq* v_next

        pointers to another sequences in a sequence tree. Sequence trees are 
        used to store hierarchical contour structures, retrieved by FindContours()

    int total

        the number of sequence elements

    int elem_size

        size of each sequence element in bytes

    CvMemStorage* storage

        memory storage where the sequence resides. It can be a NULL pointer.

    CvSeqBlock* first

        pointer to the first data block

    The structure CvSeq is a base for all of OpenCV dynamic data structures. 
    There are two types of sequences - dense and sparse. The base type for dense 
sequences is CvSeq and such sequences are used to represent growable 1d arrays - 
vectors, stacks, queues, and deques. They have no gaps in the middle - if 
an element is removed from the middle or inserted into the middle of the 
sequence, the elements from the closer end are shifted. Sparse sequences have 
CvSet as a base class and they are discussed later in more detail. They are 
sequences of nodes; each may be either occupied or free as indicated by the node 
flag. Such sequences are used for unordered data structures such as sets of 
elements, graphs, hash tables and so forth.