你如何删除OpenCV中的cvseq?

kyl*_*ens 5 c c++ opencv

Bradski声明"当你想删除序列时,可以使用cvClearSeq(),这是一个清除序列所有元素的例程."

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

他说"如果你想为其他目的检索那个内存,你必须通过cvClearMemStore()清除内存存储".

此功能似乎不存在:

error C3861: 'cvClearMemStore': identifier not found
Run Code Online (Sandbox Code Playgroud)

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

error C2664: 'cvClearMemStorage' : cannot convert parameter 1 from 'CvSeq *' to 'CvMemStorage *' 
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

kar*_*lip 8

我确信他的意思是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);
Run Code Online (Sandbox Code Playgroud)

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