使用opencv旋转图像时出现错误:windows has triggered a breakpoint in test.ext

来源:互联网 发布:仿电商微信小程序源码 编辑:程序博客网 时间:2024/05/16 15:15

出现错误时会出现下面的对话框:


出现这种问题,在一些博客中谈到两个原因:1. 访问已被释放的内存;2. 再次释放已被释放的内存;详情可以看博客:http://www.cppblog.com/wangjia184/archive/2008/03/27/45520.html

但是我遇到的问题是:访问了没有申请的空间,并在结束时释放了这些空间。

部分代码如下:

{Mat tempPlane = Mat::zeros(size,CV_8UC1);Point planeOrigin(size.width/2,size.height/2);uchar *ptempPlane = tempPlane.ptr<uchar>(0);int tempWidth = size.width,tempHeight = size.height;for(int i=0,numFrontPixel = coord.size();i<numFrontPixel;i++){//求旋转后的前景像素到目标面板中位置的映射double a = coord.at(i).x, b = coord.at(i).y;double c = sqrt(a*a+b*b);double tempx = c*cos(atan2(b,a) + angle),tempy = c*sin(atan2(b,a) + angle);double planex = planeOrigin.x + tempx , planey = planeOrigin.y - tempy;int px = planex>0.0 ? floor(planex+0.5) : ceil(planex - 0.5),py = planey>0.0 ? floor(planey+0.5) : ceil(planey - 0.5);if(px < tempWidth && px >= 0 && py>=0 && py < tempHeight)  //判断是否超界,若有越界赋值,会出现析构错误*(ptempPlane + py*tempWidth + px) = 255;}...........................}


这里是使用opencv进行图像绕中心旋转的部分代码。出问题主要是之前if语句写错了。


if(planex < tempWidth && planex >= 0 && planey>=0 && planey < tempHeight)  //判断是否超界,若有越界赋值,会出现析构错误

这里是使用opencv进行图像绕中心旋转的部分代码。出问题主要是之前if语句写错了。
导致赋值越界了,但是这里编译器并不提示出错。等程序跳出外面的大括号的时候临时变量tempPlane被析构,没有申请的单元也被析
构,而出现了这样的错误。
这种错误也可以认为是已经被释放的空间,再次被释放。
                                             
1 0