OpenCV中的CvSepFilter是一种可分离滤波器。目前我没有找到可用文档,我通过分析代码以及用实验测试得到了以下使用经验
在实际使用中,可以通过分别设定X方向滤波算子与y方向滤波算子进行工作,X算子与Y算子是独立工作
//初始化一个CvSepFilter,设置其行为
CvSepFilter::init(
int _max_width,
int _src_type,
int _dst_type,
const CvMat* _kx,
const CvMat* _ky,
CvPoint _anchor=cvPoint(-1,-1),
int _border_mode=IPL_BORDER_REPLICATE,
CvScalar _border_value=cvScalarAll(0)
);
_max_width 欲处理图像的最大宽度
_src_type 源图像的类型
_dst_type 结果图像的类型
_kx x方向的滤波器
_ky y方向的滤波器
_anchor (-1,-1)表示滤波器处于中心
否则 x 表示x算子中心
y 表示y算子中心
_border_mode 尚不知目的
_border_value 尚不知目的
CvBaseImageFilter::process(
const CvMat* _src,
CvMat* _dst,
CvRect _src_roi=cvRect(0,0,-1,-1),
CvPoint _dst_origin=cvPoint(0,0),
int _flags=0 );
_src 待处理的图像
_dst 处理结果
_src_roi 原图待处理的roi
(0,0,-1,-1)表示全图
_dst_origin 处理结果的起始坐标
_flags
CV_START means that the input is the first (top) stripe of the processed image [roi],
CV_END - the input is the last (bottom) stripe of the processed image [roi],
CV_MIDDLE - the input is neither first nor last stripe.
CV_WHOLE - the input is the whole processed image [roi].
初始一个sobel算子
CvSepFilter::init_deriv(
int _max_width,
int _src_type,
int _dst_type,
int dx,
int dy,
int aperture_size,
int flags=0 )
_max_width 欲处理图像的最大宽度
_src_type 源图像的类型
_dst_type 结果图像的类型
dx 0 表示不对x方向滤波
1 对 x 方向进行滤波
dy
0 表示不对y方向滤波
1 对 y 方向进行滤波
aperture_size 滤波器大小 为1 时 滤波器为(-1,0,1)
使用代码
float array1[]={1,1};
CvMat * kernalx = cvCreateMat(1,2,CV_32FC1);
cvSetData(kernalx,array1,kernalx->step);
float array2[]={-1,1};
CvMat * kernaly = cvCreateMat(1,2,CV_32FC1);
cvSetData(kernaly,array2,kernaly->step);
CvSepFilter Px;//,cvPoint(1,1)
Px.init(src_mat->width,src_mat->type,dst_mat->type,kernalx,kernaly,cvPoint(1,1));
Px.process(src_mat,dst_mat);
以上所有数据为个人使用经验,并无可靠文档,如果错误,请指出,谢谢!