Opencv cvcreateglcm () is used to calculate the memory error of the gray level co-occurrence matrix.

Source: Internet
Author: User

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:

  1. Cv_call (newglcm = (cvglcm *) cvalloc (sizeof (cvglcm); // obtain the size of the struct here
  2. 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:

  1. // Delete [] marginalprobability;
  2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.