I wrote a post on the Internet to say this problem. I didn't call it at the beginning. Later, I tried debugging in the source code, which is really troublesome.
After debugging the original cvtexture. CPP, the problem is found in the icvcreateglcm_lookuptable_8u_c1r function, which is caused by out-of-bounds memory allocation.
After browsing the code, the following questions are raised:
1. When the cvglcm struct is dynamically created in the cvcreateglcm function:
1. cv_call (newglcm = (cvglcm *) cvalloc (sizeof (newglcm )));
2. memset (newglcm, 0, sizeof (newglcm ));
Obviously there is an error with the dynamically applied memory. The changes are as follows:
- Cv_call (newglcm = (cvglcm *) cvalloc (sizeof (cvglcm); // obtain the size of the struct here
- Memset (newglcm, 0, sizeof (cvglcm ));
2. In the icvcreateglcm_lookuptable_8u_c1r function
1. cv_call (matrices [steploop] = (double **) cvalloc (sizeof (matrices [0]) * matrixsidelength ));
2. cv_call (matrices [steploop] [0] = (double *) cvalloc (sizeof (matrices [0] [0]) * matrixsidelength ));
3. memset (matrices [steploop] [0], 0, matrixsidelength * sizeof (matrices [0] [0]);
The size of the created one-dimensional two-dimensional array (cvalloc) is incorrect. The corrections are as follows:
1. cv_call (matrices [steploop] = (double **) cvalloc (sizeof (matrices [0] [0]) * matrixsidelength ));
2. cv_call (matrices [steploop] [0] = (double *) cvalloc (sizeof (matrices [0] [0] [0]) * matrixsidelength ));
3. memset (matrices [steploop] [0], 0, matrixsidelength * sizeof (matrices [0] [0] [0]);
3. In the icvcreateglcmdescriptors_allowdoublenest function, use cvalloc to apply for memory, but use Delete [] to release memory. An error occurs.
The corrections are as follows:
- // Delete [] marginalprobability;
- Cvfree (& marginalprobability );
After the above three items are corrected, the program can get the results, but the correctness of the results is not verified.
In addition, the problem is how to modify this issue. Generally, the opencv1.0 or 2.0 EXE installed has a _ make folder under the installation directory, which contains the opencv source code project file, open and find cvtexture under the cvaux sub-project. CPP file. modify it.
After modifying the file, you must recompile the opencv project to generate a new DLL file.
If the feature value of the calculation is not verified, a batch processing is performed. During the processing process, the memory is eaten up and the source code is checked again. The memory is not released.
After debugging cvreleaseglcm (), the function is not entered. Later, I gave up using opencv to calculate the gray-scale co-occurrence matrix. I wrote one myself, and the speed may be slow.