AvicMat Kernel Type Detection Function: getKernelType()
/**\n * \brief Calculates the type of the given kernel matrix.\n * \param _kernel The kernel matrix.\n * \param anchor The anchor point of the kernel.\n * \return The type of the kernel.\n /\nint getKernelType(const AvicMat _kernel, AvicPoint2i anchor)\n{\n\n\t\tint i, sz = _kernel->rows*_kernel->cols;\n\n\tAvicMat* kernel = avic_mat(_kernel->rows, _kernel->cols, AVICCV_64FC1);\n\tavic_convertTo(_kernel, kernel);\n\n\t// // printf("%d, %d\n", anchor.x, anchor.y);\n\n\tconst double* coeffs = (double*)kernel->data.db;\n\tdouble sum = 0;\n\tint type = KERNEL_SMOOTH + KERNEL_INTEGER;\n\tif ((_kernel->rows == 1 || _kernel->cols == 1) &&\n\t\tanchor.x * 2 + 1 == _kernel->cols &&\n\t\tanchor.y * 2 + 1 == _kernel->rows)\n\t\ttype |= (KERNEL_SYMMETRICAL + KERNEL_ASYMMETRICAL);\n\n\tfor (i = 0; i < sz; i++)\n\t{\n\t\tdouble a = coeffs[i], b = coeffs[sz - i - 1];\n\t\tif (a != b)\n\t\t\ttype &= ~KERNEL_SYMMETRICAL;\n\t\tif (a != -b)\n\t\t\ttype &= ~KERNEL_ASYMMETRICAL;\n\t\tif (a < 0)\n\t\t\ttype &= ~KERNEL_SMOOTH;\n\t\tif (a != (int)(a))\n\t\t\ttype &= ~KERNEL_INTEGER;\n\t\tsum += a;\n\t}\n\n\tif (fabs(sum - 1) > FLT_EPSILON*(fabs(sum) + 1))\n\t\ttype &= ~KERNEL_SMOOTH;\n\tavic_destroy_mat(kernel);\n\treturn type;\n}\n
原文地址: https://www.cveoy.top/t/topic/hocr 著作权归作者所有。请勿转载和采集!