Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv FindContours函数_C_Opencv - Fatal编程技术网

Opencv FindContours函数

Opencv FindContours函数,c,opencv,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

我尝试用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;
}
我有一个错误:“大小”未声明(首次在此函数中使用)

请提供任何帮助。

CvSeq是一个。它没有属性“size”,但有属性“total”。也许这就是你想要的

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.

请停止使用不推荐使用的c-api。在不久的将来不会有人支持它。是的,它可以工作,但它给出的数字不匹配。我有一个对象在我的形象和给我106。