opencv+cuda内存泄露错误

来源:互联网 发布:linux进程调度 编辑:程序博客网 时间:2024/05/21 08:00

在编写的模版中,利用opencv进行拷贝图像data时,报错如下:

Unhandled exception at 0x74dec42d in XXXX_CUDA.exe: 

Microsoft C++ exception: cv::Exception at memory location 0x0017f878.

定位到错误在:

cvReleaseImage( &copy_y );也就是说释放图像数据是时候,发生内存非法读写;

template<class T>void grad_y( const IplImage *img, IplImage *grad, const IplImage *mask ){    IplImage *copy_y = cvCloneImage( img );int h = img->height;int w = img->width;int channel = img->nChannels;cvZero( grad );for(int i=1;i<h;++i)for(int j=0;j<w;++j){    //.....此处代码没有错误}   cvReleaseImage( &copy_y );
经过查阅文献,不少人遇到类似问题,结论为opencv本身bug;奇怪的是,我将
IplImage *copy_y = cvCloneImage( img );
改为:
IplImage *copy_y =NULL;copy_y = cvCloneImage( img );

问题解决了,经多次测试,bug不会再复现,百思不得其解;

1 0
原创粉丝点击