---
title: kml_init_filter
description: "filter2D计算资源初始化。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0713.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0713.html
indexId: 0c94977ce5471b0faff81855a275d15666412bedd065432447fbd70cc45bde7261
---
# kml_init_filter

filter2D计算资源初始化。

#### 接口定义

C interface：


int kml_init_filter(cvhalFilter2D **context, unsigned char *kernel_data, size_t kernel_step, int kernel_type, int kernel_width, int kernel_height, int max_width, int max_height, int src_type, int dst_type, int borderType, double delta, int anchor_x, int anchor_y, bool allowSubmatrix, bool allowInplace);

#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| context | cvhalFilter2D \*\* | 空结构体指针，完成资源初始化后，指向内部申请的资源结构体空间 | 输入/输出 |
| kernel\_data | unsigned char\* | 卷积核数据 | 输出 |
| kernel\_step | size\_t | 卷积核每行数据的字节数 | 输入 |
| kernel\_width | int | 卷积核的宽度 | 输入 |
| kernel\_height | int | 卷积核的高度 | 输入 |
| max\_width | int | 完整图像宽度 | 输入 |
| max\_height | int | 完整图像高度 | 输入 |
| src\_type | int | 输入图像类型 | 输入 |
| dst\_type | int | 输出图像类型 | 输入 |
| borderType | int | 边界填充类型 | 输入 |
| delta | double | 添加在输出图像的偏置值 | 输入 |
| anchor\_x | int | 滤波起始点在卷积核中的宽度方向的相对坐标 | 输入 |
| anchor\_y | int | 滤波起始点在卷积核中的高度方向的相对坐标 | 输入 |
| allowSubMatrix | bool | 是否支持输入图像是子矩阵， true表示支持，false表示不支持 | 输入 |
| allowInplace | bool | 是否支持inplace运算， true表示支持，false表示不支持 | 输入 |


函数接口入参由OpenCV filter2D上层对入参处理传入，kml_init_filter不支持用户显式调用。


#### 返回值

| 场景 | 返回值 |
| --- | --- |
| 输入图像深度、输出图像深度不为CV\_16F或CV\_32F | 1 |
| 卷积核通道数不等于1 | 1 |
| 传入OpenCV filter2D接口的边界填充类型不在以下列表中： BORDER\_CONSTANT BORDER\_REPLICATE BORDER\_REFLECT BORDER\_REFLECT\_101 BORDER\_REFLECT101 BORDER\_DEFAULT BORDER\_ISOLATED | 1 |
| 内部资源申请失败 | \-1 |
| 其余场景 | 0 |
