c++ - 你如何删除 OpenCV 中的 cvseq?

标签 c++ c opencv

Bradski 说“当你想删除一个序列时,你可以使用 cvClearSeq(),一个清除序列所有元素的例程。”

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

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

这个函数似乎不存在:

error C3861: 'cvClearMemStore': identifier not found

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

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

有什么想法吗?

最佳答案

我确信他指的是 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.

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

从错误中可以看出,您向此函数传递了错误的数据类型。 <强> Check the docs 这些函数,以便确切地知道如何调用它们。

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

// 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 的使用。我找到了 this one很有趣。帖子底部有一个指向源代码的链接。

关于c++ - 你如何删除 OpenCV 中的 cvseq?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951292/

相关文章:

c - malloc(sizeof(struct xxxx)) 没有分配任何内存

c++ - OpenCV imshow() 循环显示图像

matlab - OpenCV:从多个 float 组创建直方图

python - 在 PyQt 的主窗口之上显示 OpenCv 窗口

c++ - 在 C++ 中重新定义与覆盖

c++ - CMake - 无法链接共享库(子目录)

c++ - Qt:文件读取不起作用

c - Arduino fsr 保持值(value)

c - 地址的数据大小

c++ - 抽象类中的纯虚函数,返回类型为基/派生类型