注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

斗天堂

douzsh还活着

 
 
 

日志

 
 

zz OpenCV 1.0 cvtexture.cpp bug 修正 内存错误  

2011-01-21 18:27:23|  分类: 算法 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

  Three bugs found in GLCM about texture analysis

老外发现的opencv中cvtexture中的三个bug  出处:http://tech.groups.yahoo.com/group/OpenCV/messages/18038?threaded=1&m=e&var=1&tidx=1
Hello everybody,  I ever delivered two articles about GLCM, asking about how to use it(exactly the meaning of the structure member and the meaning of
the function parameters, see 17848).It seems few people are dealing with it and so no one answered me. It is said that you can count on
yourself if no one can be relied on. So I read the whole source code. Fortunately, I have comprehended 90% of them and found 3 bugs
which are listed below. Anyone who is dealing with texture analysis is welcome to get contact with me. We can communicate with each
other. And two heads are always better than one head. Best wishes to everyone~!
In the file “cvtexture.cpp”
(1).In the function “cvCreateGLCM()”,when we allocate memory to the pointer of structure GLCM, “newGLCM”. A mistake was made here.
The original code is:
  1. CV_CALL(newGLCM=(CvGLCM*)cvAlloc(sizeof(newGLCM)));  
  2.  memset( newGLCM, 0, sizeof(newGLCM) );  

The right one is:
  1. CV_CALL( newGLCM = (CvGLCM*)cvAlloc(sizeof(CvGLCM)));  
  2. memset( newGLCM, 0, sizeof(CvGLCM) );  
(2).In the function “icvCreateGLCM_LookupTable_8u_C1R()”,when we allocate memory to one member of structure GLCM, double ***matrices.
Here appears another mistake. They should be replaced by the commentary.

  1.    CV_CALL(matrices[stepLoop]=(double**)cvAlloc( sizeof(matrices[0])*matrixSideLength ));//BUG!  
  2.   
  3. //CV_CALL(matrices[stepLoop]=(double**)cvAlloc( sizeof(matrices[0][0])*matrixSideLength ));  
  4.   
  5.   
  6.    CV_CALL(matrices[stepLoop][0]=(double*)cvAlloc (sizeof(matrices[0][0])matrixSideLength*matrixSideLength ));//BUG!  
  7. //CV_CALL(matrices[stepLoop][0]=(double*)cvAlloc ( sizeof(double)*matrixSideLength*matrixSideLength ));  
  8.   
  9.   
  10.   
  11. memset(matrices[stepLoop]0],0,matrixSideLength*matrixSideLength*sizeof(matrices[0][0]) );//BUG  
  12.   //memset(matrices[stepLoop][0],0,atrixSideLength*matrixSideLength*sizeof(double));  

(3)In the function “icvCreateGLCMDescriptors_AllowDoubleNest()”,the last statement “delete [] marginalProbability;”should be replaced by 
cvFree( (void**)&marginalProbability);” Because the forward statement 
“double*marginalProbability=(double*)cvAlloc(matrixSideLength*sizeof(marginalProbability[0]));”.Allocation of memory should be coincided with 
the release of memory.“malloc” with “free”,and “new” with“delete”.  That’s all. Thank you for your attention~!
我按照上面所说的修改完三个bug所确实可以运行,但有个严重的问题,那就是内存泄漏,检测一个几分钟的视频内存都被吸光了,机子动不了,只能关机重启。
经过断点排查,原来cvReleaseGLCM函数中还有一个bug,就是  
  1. if(*GLCM)  
  2.    EXIT; // repeated deallocation: just skip it.  
应该改为
  1. if(!(*GLCM))  
  2.     EXIT; // repeated deallocation: just skip it.  
这样,opencv的纹理检测就完善了。
目前还存在问题,对于二值图像的检测会报错,继续debuging,发现仍然存在两个问题,在函数icvCreateGLCMDescriptors_AllowDoubleNest中,
marginalProbabilityEntropy += marginalProbability[ actualSideLoop1 ]*log(marginalProbability[ actualSideLoop1 ]);
double HXYValue = marginalProbability[ actualSideLoop1 ] * marginalProbability[ actualSideLoop2 ];
应该修改为:
marginalProbabilityEntropy += marginalProbability[ sideLoop1 ]*log(marginalProbability[ sideLoop1 ]);
double HXYValue = marginalProbability[ sideLoop1 ] * marginalProbability[ sideLoop2 ];
 
这在一个日本人的代码中看到了修改,但是没看到相应的介绍网页。
  评论这张
 
阅读(669)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017