GLCM in opencv2 (Gray-Level Co-occurrence Matrices)

匆匆过客 提交于 2019-12-06 13:34:01

问题


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 !


回答1:


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.




回答2:


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);



回答3:


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



来源:https://stackoverflow.com/questions/24875929/glcm-in-opencv2-gray-level-co-occurrence-matrices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!