1

The legacy function GLCM does not perform yet in opencv2. I use the following code:

#import <opencv2/legacy.hpp>

cv::Mat inputIm = [in_image CVMat];
cv::Mat grayIm = [in_image CVGrayscaleMat];

// cv::cvtColor(inputIm, grayIm, cv::COLOR_RGB2GRAY);

// here I get an error: "no matching function..." !!!
CvGLCM* glcm = cvCreateGLCM(grayIm, 1, NULL, 4, CV_GLCM_OPTIMIZATION_LUT);

cvCreateGLCMDescriptors(glcm, CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST);
double d = cvGetGLCMDescriptor(glcm, 0, CV_GLCMDESC_HOMOGENITY );
double a = 1; double *ave = &a;
double s = 1; double *sd = &s;
cvGetGLCMDescriptorStatistics(glcm, CV_GLCMDESC_ENERGY, ave, sd);

NSLog(@"ave = %f sd = %f", *ave, *sd);

I tried already to use the namespace cv::CvGLCM* glcm = cv::cvCreateGLCM(grayIm,.... -- but no change :/

Any help on this is very much appreciated !

Tonechas
  • 13,398
  • 16
  • 46
  • 80
iKK
  • 6,394
  • 10
  • 58
  • 131

3 Answers3

3

What helped finally was the answer from Alexander Shishkov posted here: link1

I did exchange the texture.cpp code and compiled my opencv-framework again (explained here: link2: i.e. in particular I re-did the last step of the three...).

Doing all that, my glcm-code performs without exception and delivers two numbers per glcm-method.

iKK
  • 6,394
  • 10
  • 58
  • 131
1

The legacy function cvCreateGLCM takes the older IplImage* as its input, so you need to convert your cv::Mat image first.

Try this:

// your input image
cv::Mat grayIm = [in_image CVGrayscaleMat];

// create a legacy image
IplImage pGray = grayIm;

// call function
CvGLCM* glcm = cvCreateGLCM(&pGray, 1, NULL, 4, CV_GLCM_OPTIMIZATION_LUT);
Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • Works a wee bit better now, thank you! But somehow cvCreateGLCM still brings an error: "EXC_BAD_ACCESS (code=1), address=0xdbF31e8". Any idea what I am still missing ? – iKK Jul 22 '14 at 10:25
1

I found this when I was looking for GLCM "Implementation of GLCM Haralick Features in openCV", this gets 12 of 14 texture features

https://github.com/Abello966/opencv-haralickfeatures

jjgarsal
  • 11
  • 2
  • Links to outside areas as answers are discouraged because the answer will not be guaranteed to be around forever. Please provide specifics of the answer in the body of your response, with a link to outside for the code, but your answer needs to stand on its own. I can't comment on whether your answer directly addresses the question as I don't know anything about the domain area. – Alan May 10 '18 at 00:55
  • That's a link to a third-party library, *Alan* : use of the third-party library would render the question moot in favour of a - presumably - better-tested piece of code. --- On the other hand, the OP's own, accepted, answer describes (1) fixing the code in OpenCV - which _is_ broken - according to advice that is linked to but not explained here (2) re-compiling OpenCV with this fixed source code. – WillC Nov 11 '18 at 10:39