OpenCV中滤波器学习笔记(一)--CvSepFilter

本文档介绍了OpenCV中的CvSepFilter,一种可分离滤波器。通过代码分析和实验,展示了如何初始化和使用该滤波器进行X方向和Y方向的独立滤波操作。详细讲解了CvSepFilter::init和CvBaseImageFilter::process方法,以及如何创建和应用Sobel算子。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);


以上所有数据为个人使用经验,并无可靠文档,如果错误,请指出,谢谢!

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值