我在做this example。我遇到的问题是应用程序的内存消耗,它开始大约180 MB,在30秒内达到1.5 GB。
void VideoCaptureCV::update()
{
cap >> frame; // cap is cv::VideoCapture
if(_img == 0)
{
_img = new CvMat(frame);
}
CvArr *arr = _img;
CvMat *arrMat, *cvimage, stub;
arrMat = cvGetMat(arr, &stub);
cvimage = cvCreateMat(arrMat->rows, arrMat->cols, CV_8UC3);
cvConvertImage(arrMat, cvimage, 0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex_uid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, cvimage->cols, cvimage->rows,0, GL_BGR, GL_UNSIGNED_BYTE, cvimage->data.ptr);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
w = cvimage->cols;
h = cvimage->rows;
// non of the following works correctly, it sends
// exception: cv::Exception at memory location
//cvRelease(&arr);
//cvReleaseMat(&arrMat);
//cvReleaseMat(&cvimage);
//cvReleaseMat(&stub);
}
关于如何正确使用cvRelease的任何想法?
编辑1:添加了使用cvRelease时发送的错误
答案 0 :(得分:1)
if(_img == 0)
{
_img = new CvMat(frame);
}
CvArr *arr = _img;
这如何编译?
您无需使用openCV图像调用new
,他们将为您处理memory management,只需在堆栈上本地创建图像并让openCV清理