There is error with cvAlloc in this code. See the following page: http://tech.dir.groups.yahoo.com/group/OpenCV/message/67611?var=1
You should change /opencv/modules/legacy/src/texture.cpp file to the next:
/*******************************************************************************\
*********\
Calculation of a texture descriptors from GLCM (Grey Level Co-occurrence
Matrix'es)
The code was submitted by Daniel Eaton [danieljameseaton@...]
\*******************************************************************************\
*********/
//#include "_cvaux.h"
//#include "legacy.h"
#include "precomp.hpp"
#define CV_MAX_NUM_GREY_LEVELS_8U 256
struct CvGLCM
{
int matrixSideLength;
int numMatrices;
double*** matrices;
int numLookupTableElements;
int forwardLookupTable[CV_MAX_NUM_GREY_LEVELS_8U];
int reverseLookupTable[CV_MAX_NUM_GREY_LEVELS_8U];
double** descriptors;
int numDescriptors;
int descriptorOptimizationType;
int optimizationType;
};
static void icv_CreateGLCM_LookupTable_8u_C1R( const uchar* srcImageData, int
srcImageStep, CvSize srcImageSize,
CvGLCM* destGLCM, int* steps, int numSteps, int* memorySteps );
static void icv_CreateGLCMDescriptors_AllowDoubleNest( CvGLCM* destGLCM, int
matrixIndex );
CvGLCM* cvCreateGLCM( const IplImage* srcImage, int stepMagnitude, const int* srcStepDirections,/* should be static array..or if not the user should handle de-allocation */ int numStepDirections, int optimizationType )
{
static const int defaultStepDirections[] = { 0,1,-1,1,-1,0,-1,-1 };
int* memorySteps = 0;
CvGLCM* newGLCM = 0;
int* stepDirections = 0;
CV_FUNCNAME( "cvCreateGLCM" );
__BEGIN__;
uchar* srcImageData = 0;
CvSize srcImageSize;
int srcImageStep;
int stepLoop;
const int maxNumGreyLevels8u = CV_MAX_NUM_GREY_LEVELS_8U;
if( !srcImage )
CV_ERROR( CV_StsNullPtr, "" );
if( srcImage->nChannels != 1 )
CV_ERROR( CV_BadNumChannels, "Number of channels must be 1");
if( srcImage->depth != IPL_DEPTH_8U )
CV_ERROR( CV_BadDepth, "Depth must be equal IPL_DEPTH_8U");
// no Directions provided, use the default ones - 0 deg, 45, 90, 135
if( !srcStepDirections )
{
srcStepDirections = defaultStepDirections;
}
//CV_CALL( stepDirections = (int*)cvAlloc(numStepDirections*2*sizeof(stepDirections[0])));
CV_CALL( stepDirections = new int
[numStepDirections*2*sizeof(stepDirections[0])]);
memcpy( stepDirections, srcStepDirections,
numStepDirections*2*sizeof(stepDirections[0]));
cvGetImageRawData( srcImage, &srcImageData, &srcImageStep, &srcImageSize );
// roll together Directions and magnitudes together with knowledge of image (step)
// CV_CALL( memorySteps = (int*)cvAlloc(numStepDirections*sizeof(memorySteps[0])));
CV_CALL( memorySteps = new int [ numStepDirections*sizeof(memorySteps[0]) ]);
for( stepLoop = 0; stepLoop < numStepDirections; stepLoop++ )
{
stepDirections[stepLoop*2 + 0] *= stepMagnitude;
stepDirections[stepLoop*2 + 1] *= stepMagnitude;
memorySteps[stepLoop] = stepDirections[stepLoop*2 + 0]*srcImageStep +
stepDirections[stepLoop*2 + 1];
}
//CV_CALL( newGLCM = (CvGLCM*)cvAlloc(sizeof(newGLCM)));
CV_CALL( newGLCM = new CvGLCM [sizeof(newGLCM)] );
memset( newGLCM, 0, sizeof(newGLCM) );
newGLCM->matrices = 0;
newGLCM->numMatrices = numStepDirections;
newGLCM->optimizationType = optimizationType;
if( optimizationType <= CV_GLCM_OPTIMIZATION_LUT )
{
int lookupTableLoop, imageColLoop, imageRowLoop, lineOffset = 0;
// if optimization type is set to lut, then make one for the image
if( optimizationType == CV_GLCM_OPTIMIZATION_LUT )
{
for( imageRowLoop = 0; imageRowLoop < srcImageSize.height;
imageRowLoop++, lineOffset += srcImageStep )
{
for( imageColLoop = 0; imageColLoop < srcImageSize.width;
imageColLoop++ )
{
newGLCM->forwardLookupTable[srcImageData[lineOffset+imageColLoop]]=1;
}
}
newGLCM->numLookupTableElements = 0;
for( lookupTableLoop = 0; lookupTableLoop < maxNumGreyLevels8u;
lookupTableLoop++ )
{
if( newGLCM->forwardLookupTable[ lookupTableLoop ] != 0 )
{
newGLCM->forwardLookupTable[ lookupTableLoop ] =
newGLCM->numLookupTableElements;
newGLCM->reverseLookupTable[ newGLCM->numLookupTableElements
] =
lookupTableLoop;
newGLCM->numLookupTableElements++;
}
}
}
// otherwise make a "LUT" which contains all the gray-levels (forcode-reuse)
else if( optimizationType == CV_GLCM_OPTIMIZATION_NONE )
{
for( lookupTableLoop = 0; lookupTableLoop <maxNumGreyLevels8u;
lookupTableLoop++ )
{
newGLCM->forwardLookupTable[ lookupTableLoop ] =
lookupTableLoop;
newGLCM->reverseLookupTable[ lookupTableLoop ] =
lookupTableLoop;
}
newGLCM->numLookupTableElements = maxNumGreyLevels8u;
}
newGLCM->matrixSideLength = newGLCM->numLookupTableElements;
icv_CreateGLCM_LookupTable_8u_C1R( srcImageData, srcImageStep,srcImageSize,newGLCM, stepDirections,numStepDirections, memorySteps );
}
else if( optimizationType == CV_GLCM_OPTIMIZATION_HISTOGRAM )
{
CV_ERROR( CV_StsBadFlag, "Histogram-based method is not implemented" );
/* newGLCM->numMatrices *= 2;
newGLCM->matrixSideLength = maxNumGreyLevels8u*2;
icv_CreateGLCM_Histogram_8uC1R( srcImageStep, srcImageSize,
srcImageData,
newGLCM, numStepDirections,
stepDirections, memorySteps );
*/
}
__END__;
delete[] memorySteps;
delete[] stepDirections;
if( cvGetErrStatus() < 0 )
{
cvFree( &newGLCM );
}
return newGLCM;
}
void
cv_ReleaseGLCM( CvGLCM** GLCM, int flag )
{
CV_FUNCNAME( "cvReleaseGLCM" );
__BEGIN__;
int matrixLoop ...
(more)