Three bugs in cvtexture in opencv discovered by foreigners: 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
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:
Cv_call (newglcm = (cvglcm *) cvalloc (sizeof (newglcm); memset (newglcm, 0, sizeof (newglcm ));
The right one is:
Cv_call (newglcm = (cvglcm *) cvalloc (sizeof (cvglcm); 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.
CV_CALL(matrices[stepLoop]=(double**)cvAlloc( sizeof(matrices[0])*matrixSideLength ));//BUG!//CV_CALL(matrices[stepLoop]=(double**)cvAlloc( sizeof(matrices[0][0])*matrixSideLength )); CV_CALL(matrices[stepLoop][0]=(double*)cvAlloc (sizeof(matrices[0][0])matrixSideLength*matrixSideLength ));//BUG!//CV_CALL(matrices[stepLoop][0]=(double*)cvAlloc ( sizeof(double)*matrixSideLength*matrixSideLength ));memset(matrices[stepLoop]0],0,matrixSideLength*matrixSideLength*sizeof(matrices[0][0]) );//BUG //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~!
I have modified the three bugs mentioned above and can indeed run them, but there is a serious problem, that is, memory leakage. I have detected that the video memory has been absorbed for a few minutes, the host cannot be moved. It can only be shut down and restarted.
After breakpoint troubleshooting, A bug exists in the cvreleaseglcm function, that isIf (* GLCM) Exit; // repeated deallocation: just skip it.
Should be changed
if(!(*GLCM)) EXIT; // repeated deallocation: just skip it.
Recently, an error is reported when a binarization image is used to extract texture features. The original function icvcreateglcmdescriptors_allowdoublenest has a vulnerability. The modification is as follows:
Original code:
marginalProbabilityEntropy += marginalProbability[ actualSideLoop1 ]*log(marginalProbability[ actualSideLoop1 ]);double HXYValue = marginalProbability[ actualSideLoop1 ] * marginalProbability[ actualSideLoop2 ];
It should be changed:
marginalProbabilityEntropy += marginalProbability[ sideLoop1 ]*log(marginalProbability[ sideLoop1 ]);double HXYValue = marginalProbability[ sideLoop1 ] * marginalProbability[ sideLoop2 ];
In this way, the texture detection of opencv is improved.