在编写的模版中,利用opencv进行拷贝图像data时,报错如下:
Unhandled exception at 0x74dec42d in XXXX_CUDA.exe:
Microsoft C++ exception: cv::Exception at memory location 0x0017f878.
定位到错误在:
cvReleaseImage( ©_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( ©_y );
经过查阅文献,不少人遇到类似问题,结论为opencv本身bug;奇怪的是,我将IplImage *copy_y = cvCloneImage( img );改为:
IplImage *copy_y =NULL; copy_y = cvCloneImage( img );
问题解决了,经多次测试,bug不会再复现,百思不得其解;
原文地址:http://blog.csdn.net/gggg_ggg/article/details/48131747