难道大家没有疑惑?
在编程之前,究竟要包含哪几个头文件呢?
先看一下各模块包含有什么
core: 一些基本数据结构,如矩阵,向量等。这部分很重要,一定要比较熟悉,特别是矩阵类型Mat, 就像Matlab里面的矩阵对matlab的作用一样。
highgui: 一些图像、视频的读、写、显示接口。2.0版本后改装的有点像Matlab的函数。如读写图像的imread, imwrite跟matlab一模一样。
imgproc: 正如其名,是图像处理模块,有常见的图像处理功能,如滤波,变换等。
features2d: 图像的特征检测,描述等。如SIFT,SURF等。
calib3d: 摄像机标定,图像配准,三维重建等,
objdetect: 对象检测。
ml: 机器学习模块,有各种主流分类器,如SVM,贝叶斯,神经网络,boosting等。
flann: 寻找k近邻的快速算法
gpu: gpu加速
===========我只是想插入 ===========
當然啊,這篇日誌發的時候已經2.4.5了。
我最近在做的超分辨率也加入了。
好期待再多幾個功能啊,
這樣我的畢業論文就輕鬆很多
啊哈哈哈
=========================
这两个应该是必备的
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
然后就各取所需咯
参阅资料:
科研工具
http://vcc.siat.ac.cn/zh/%E7%A7%91%E7%A0%94%E5%B7%A5%E5%85%B7/
另外还分享一个小白问题
为啥无法调试,每次都要直接启动程序才能运行成功,
装载图片那一段如果是单步调试都是出错?
问题已解决,
working dierctory应该指向项目目录,而不是debug.
请参阅:
http://www.opencv.org.cn/forum/viewtopic.php?t=14306
【10】Smoothing.cpp
E:\Program Files\OpenCV2.3.1\opencv\samples\cpp\tutorial_code\ImgProc
原理啊,献上真相
Original Image
真理就是:
==================================
不妨把 滤波器 想象成一个包含加权系数的窗口,
当使用这个滤波器平滑处理图像时,
就把这个窗口滑过图像。
就是所謂的空間濾波啦!!!
=================================
1 归一化块滤波器 (Normalized Box Filter)
最简单的滤波器, 输出像素值是核窗口内像素值的 均值 ( 所有像素加权系数相等)
void blur(const Mat& src, Mat& dst, Size ksize, Point anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)
Parameters:
src – 原图像
dst – 目标图像; 和原图像同样大小
ksize – 滤波矩形核 ksize.height ksize.width
anchor – anchor为定标点,如果采用的是Point(-1,-1)则默认为核的中心点,
borderType – 边缘模式的展开
Homogeneous Blur
2 高斯滤波器 (Gaussian Filter)
最有用的滤波器 (尽管不是最快的)。
void GaussianBlur(const Mat& src, Mat& dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT)
Parameters:
src – The source image
dst – The destination image; will have the same size and the same type as src
ksize – 高可以不一样,但高和宽都必须是奇数,或者,也可以是零,否则由sigma计算得出
sigmaX, sigmaY – 方向标准方差
borderType – The pixel extrapolation method; see borderInterpolate()
Gaussian Blur
通过高斯分布的曲线可以发现,
离目标像素越近的点对最终结果的贡献越大,反之则越小。
在低通滤波算法中有不错的表现,
但是其却有另外一个问题,
那就是只考虑了像素间的空间位置上的关系,
因此滤波的结果会丢失边缘的信息。
3 中值滤波器 (Median Filter)
中值滤波将图像的每个像素用邻域 (以当前像素为中心的正方形区域)像素的 中值 代替 。
void medianBlur(const Mat& src, Mat& dst, int ksize)
Parameters:
src – The source 1-, 3- or 4-channel image. When ksize is 3 or 5, the image depth should be CV_8U , CV_16U or CV_32F . For larger aperture sizes it can only be CV_8U
dst – The destination array; will have the same size and the same type as src
ksize – The aperture linear size. It must be odd and more than 1, i.e. 3, 5, 7 ...
内核大小 (只需一个值,因为我们使用正方形窗口),必须为奇数。
Median Blur
中值滤波法对消除椒盐噪声非常有效,
在光学测量条纹图象的相位分析处理方法中有特殊作用,
但在条纹中心分析方法中作用不大.
4 双边滤波 (Bilateral Filter)
目前我们了解的滤波器都是为了 平滑 图像, 问题是有些时候这些滤波器不仅仅削弱了噪声, 连带着把边缘也给磨掉了。 为避免这样的情形 (至少在一定程度上 ), 我们可以使用双边滤波。
类似于高斯滤波器,双边滤波器也给每一个邻域像素分配一个加权系数。 这些加权系数包含两个部分, 第一部分加权方式与高斯滤波一样,第二部分的权重则取决于该邻域像素与当前像素的灰度差值。
void bilateralFilter(const Mat& src, Mat& dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT)
Parameters:
src – The source 8-bit or floating-point, 1-channel or 3-channel image
dst – The destination image; will have the same size and the same type as src
d – The diameter of each pixel neighborhood, that is used during filtering. If it is non-positive, it’s computed from sigmaSpace 像素的邻域直径
sigmaColor – Filter sigma in the color space. Larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace ) will be mixed together, resulting in larger areas of semi-equal color 颜色空间的标准方差
sigmaSpace – Filter sigma in the coordinate space. Larger value of the parameter means that farther pixels will influence each other (as long as their colors are close enough; see sigmaColor ). Then d>0 , it specifies the neighborhood size regardless of sigmaSpace , otherwise d is proportional to sigmaSpace 坐标空间的标准方差(像素单位)
Bilateral Blur
是不是很有油畫的感覺!!!
Bilateral就是在Gaussian blur中加入了另外的一个权重分部来解决
Gaussian blur会丢失图像中主要的不同颜色区域边缘
Bilateral加入了相似程度分部
可以将源图像左侧那些跟当前像素差值过大的点给滤去,
这样就很好地保持了边缘。
请参阅:
http://blog.youkuaiyun.com/bugrunner/article/details/7170471
关于borderType
borderType:边界类型,来决定如何赋值新增加的边界。
BORDER_CONSTANT:使用常数(value参数)填充边界(默认为0)
BORDER_REPLICATE:复制图像最邻近的行或列
value:如果类型为BORDER_CONSTANT时,新增像素赋值为value,默认为0。
请参阅:
opencv源码解析之(2):滤波前言2
http://www.cnblogs.com/tornadomeet/archive/2012/03/05/2379921.html