gpt4 book ai didi

c - Opencv FindContours函数

转载 作者:行者123 更新时间:2023-11-30 17:42:43 25 4
gpt4 key购买 nike

我尝试使用 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”未声明(在此函数中首次使用)

请提供任何帮助。

最佳答案

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.

关于c - Opencv FindContours函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com