好久没来了!
今天又碰到一个非常奇怪的问题!我现在先记录下来,看以后能不能解决吧!
程序段一:
for(i=mat->height-2;i>=0;i--)
for(j=1;j<mat->width;j++)
if(cvGetReal2D(mat,i,j)==0)
{
x=i;y=j;
if((cvGetReal2D(mat,x,y-1)==1)&&(cvGetReal2D(mat,x+1,y)==1))
cvSetReal2D(index,x,y,key++);
if((cvGetReal2D(mat,x,y-1)==0)&&(cvGetReal2D(mat,x+1,y)==1))
cvSetReal2D(index,x,y,cvGetReal2D(index,x,y-1));
if((cvGetReal2D(mat,x,y-1)==1)&&(cvGetReal2D(mat,x+1,y)==0))
cvSetReal2D(index,x,y,cvGetReal2D(index,x+1,y));
if((cvGetReal2D(mat,x,y-1)==0)&&(cvGetReal2D(mat,x+1,y)==0))
cvSetReal2D(index,x,y,cvGetReal2D(index,x,y-1)<cvGetReal2D(index,x+1,y)?cvGetReal2D(index,x,y-1):cvGetReal2(index,x+1,y));
}
程序段二:
for(i=mat->height-2;i>=0;i--)
for(j=1;j<mat->width;j++)
if(cvGetReal2D(mat,i,j)==0)
{
x=i;y=i;//这里写错了,应该是y=j;
if((cvGetReal2D(mat,x,y-1)==1)&&(cvGetReal2D(mat,x+1,y)==1))
cvSetReal2D(index,x,y,key++);
if((cvGetReal2D(mat,x,y-1)==0)&&(cvGetReal2D(mat,x+1,y)==1))
cvSetReal2D(index,x,y,cvGetReal2D(index,x,y-1));
if((cvGetReal2D(mat,x,y-1)==1)&&(cvGetReal2D(mat,x+1,y)==0))
cvSetReal2D(index,x,y,cvGetReal2D(index,x+1,y));
if((cvGetReal2D(mat,x,y-1)==0)&&(cvGetReal2D(mat,x+1,y)==0))
cvSetReal2D(index,x,y,cvGetReal2D(index,x,y-1)<cvGetReal2D(index,x+1,y)?cvGetReal2D(index,x,y-1):cvGetReal2(index,x+1,y));
}
这两个程序是我在不同的时间写的,都是一样的,但是奇怪的是,程序一可以正常使用,程序二就报错!检查了一上午也没发现问题!
刚在排版这篇文章的时候发现了错误!原来也是粗心!记录下来吧,以后当警告!~