如何在 OpenCV 中删除 cvseq?

发布于 2024-11-06 05:04:29 字数 499 浏览 1 评论 0原文

Bradski 指出,“当您想要删除序列时,可以使用 cvClearSeq(),这是一个清除序列中所有元素的例程。”

但是,此函数不会将内存存储中分配的块返回到存储或系统。

他说“如果您想出于其他目的检索该内存,则必须通过 cvClearMemStore() 清除内存存储”。

这个函数似乎不存在:

error C3861: 'cvClearMemStore': identifier not found

在本书的勘误表中,它指出:“'cvClearMemStore'应该是'cvClearMemStorage'”,但这个函数需要一个指向CvMemStorage的指针,而不是CvSeq。

error C2664: 'cvClearMemStorage' : cannot convert parameter 1 from 'CvSeq *' to 'CvMemStorage *' 

有什么想法吗?

Bradski states that "When you want to delete a sequence, you can use cvClearSeq(), a routine that clears all elements of the sequence."

HOWEVER, this function does not return allocated blocks in the memory store to either the store or to the system.

He says that "If you want to retrieve that memory for some other purpose, you must clear the memory store via cvClearMemStore()".

This function does not appear to exist:

error C3861: 'cvClearMemStore': identifier not found

In the errata for the book, it states that: " 'cvClearMemStore' should be 'cvClearMemStorage' " but this function expects a pointer to CvMemStorage, not CvSeq.

error C2664: 'cvClearMemStorage' : cannot convert parameter 1 from 'CvSeq *' to 'CvMemStorage *' 

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终止放荡 2024-11-13 05:04:29

我确信他的意思是 cvClearMemStorage()

清除内存存储。这是唯一的方法(!!!)(除了cvRestoreMemStoragePos)
重用为存储分配的内存 - cvClearSeq、cvClearSet ...
不要释放任何内存。
子存储在清除时将所有块返回给父存储。

从标题复制的文本: core/core_c.h

从错误中可以看出,您向此函数传递了错误的数据类型。 查看这些函数的文档以准确了解如何调用它们。

我将尝试用下面的代码进行说明:

// Create variable to hold the memory allocated for calculations
CvMemStorage* storage = 0;

// Allocate the memory storage. Param 0 will set the block size to a default value - currently it is about 64K.
storage = cvCreateMemStorage(0);

IplImage* gray = NULL; 
// <insert code to load a gray image here>

/* Retrieves contours from the binary image and returns the number of retrieved contours.
 * cvFindContours will scan through the image and store connected contours in "storage".
 * "contours" will point to the first contour detected.
 */
CvSeq* contours = 0;
cvFindContours(gray, storage, &contours );

// Clear the memory storage which was used before
cvClearMemStorage(storage);

// Release memory
cvReleaseMemStorage(&storage);

有一些教程展示了cvSeq的用法。我发现这个非常有趣。帖子底部有一个源代码链接。

I'm convinced that he meant cvClearMemStorage():

Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)
to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...
do not free any memory.
A child storage returns all the blocks to the parent when it is cleared.

Text copied from the header: core/core_c.h

As you can tell from the error, you are passing the wrong data type to this function. Check the docs of these functions to know exactly how to call them.

I'll try to illustrate with the code below:

// Create variable to hold the memory allocated for calculations
CvMemStorage* storage = 0;

// Allocate the memory storage. Param 0 will set the block size to a default value - currently it is about 64K.
storage = cvCreateMemStorage(0);

IplImage* gray = NULL; 
// <insert code to load a gray image here>

/* Retrieves contours from the binary image and returns the number of retrieved contours.
 * cvFindContours will scan through the image and store connected contours in "storage".
 * "contours" will point to the first contour detected.
 */
CvSeq* contours = 0;
cvFindContours(gray, storage, &contours );

// Clear the memory storage which was used before
cvClearMemStorage(storage);

// Release memory
cvReleaseMemStorage(&storage);

There are a few tutorials out there that shows the use of cvSeq. I found this one quite interesting. There's a link to the source code at the bottom of the post.

无畏 2024-11-13 05:04:29

看起来CVMemStorage结构被用作基本的低级结构来创建存储空间。

关于 CvMemStorage 的描述如下:

内存存储是低级的
用于动态存储的结构
不断增长的数据结构,例如
序列、轮廓、图表、
细分等

您的 struct cvSeq 包含一个指向 CVMemStorage 的指针,以告诉它存储在哪里

#define CV_SEQUENCE\_FIELDS() \
    int flags; /* micsellaneous flags */ \
    int header_size; /* size of sequence header */ \
    struct CvSeq* h_prev; /* previous sequence */ \
    struct CvSeq* h_next; /* next sequence */ \
    struct CvSeq* v_prev; /* 2nd previous sequence */ \
    struct CvSeq* v_next; /* 2nd next sequence */ \
    int total; /* total number of elements */ \
    int elem_size;/* size of sequence element in bytes */ \
    char* block_max;/* maximal bound of the last block */ \
    char* ptr; /* current write pointer */ \
    int delta_elems; /* how many elements allocated when the sequence grows
                  (sequence granularity) */ \
    CvMemStorage* storage; /* where the seq is stored */ \  //HERE!!! pointer to storage
    CvSeqBlock* free_blocks; /* free blocks list */ \
    CvSeqBlock* first; /* pointer to the first sequence block */

typedef struct CvSeq
{
    CV_SEQUENCE_FIELDS()
} CvSeq;

因此,您需要调用 CvClearMemStorage 并将指向 cvSeq 对象的 CvMemStorage 的指针传递给它,这将清除您的存储空间CvSeq 对象。

页面上对此进行了很好的解释。

It looks like the CVMemStorage structure is used as a basic low-level structure to create space to store things.

It says about CvMemStorage:

Memory storage is a low-level
structure used to store dynamicly
growing data structures such as
sequences, contours, graphs,
subdivisions, etc.

Your struct cvSeq contains a pointer to a CVMemStorage to tell it where it is stored.

#define CV_SEQUENCE\_FIELDS() \
    int flags; /* micsellaneous flags */ \
    int header_size; /* size of sequence header */ \
    struct CvSeq* h_prev; /* previous sequence */ \
    struct CvSeq* h_next; /* next sequence */ \
    struct CvSeq* v_prev; /* 2nd previous sequence */ \
    struct CvSeq* v_next; /* 2nd next sequence */ \
    int total; /* total number of elements */ \
    int elem_size;/* size of sequence element in bytes */ \
    char* block_max;/* maximal bound of the last block */ \
    char* ptr; /* current write pointer */ \
    int delta_elems; /* how many elements allocated when the sequence grows
                  (sequence granularity) */ \
    CvMemStorage* storage; /* where the seq is stored */ \  //HERE!!! pointer to storage
    CvSeqBlock* free_blocks; /* free blocks list */ \
    CvSeqBlock* first; /* pointer to the first sequence block */

typedef struct CvSeq
{
    CV_SEQUENCE_FIELDS()
} CvSeq;

So you'd need to call CvClearMemStorage and pass the pointer to the CvMemStorage of your cvSeq object to it, which will clear the storage for your CvSeq object.

It is really nicely explained on this page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文