您的位置:首页 > 运维架构

opencv入门三函数说明

2018-01-07 21:49 976 查看

函数说明

medianBlur bilateralFilter createTrackbar

medianBlur

官方说明:通过周围数据中值来进行平滑,优点效果好,就是慢就是慢

The function smoothes an image using the median filter with the

参数说明

@param src input 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.

@param dst destination array of the same size and type as src.

//内核大小只要奇数大于1

@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 …

@sa bilateralFilter, blur, boxFilter, GaussianBlur

示例

//中值滤波
int medianBlurimg(const string & filename)
{
Mat srcimg = imread(filename);
Mat dst;
medianBlur(srcimg, dst, 10 * 2 + 1);
imshow("medianBlurimg", dst);
//waitKey(0);
return 0;

}


bilateralFilter

官方说明:去燥并保证边缘完整

The function applies bilateral filtering to the input image, as described in

http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html

bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is

very slow compared to most filters.
参数说明

@param src Source 8-bit or floating-point, 1-channel or 3-channel image.

@param dst Destination image of the same size and type as src .

//象素直径如果不是正数它会从sigmaspace算出来

@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,

it is computed from sigmaSpace.

//颜色滤波数越大表示边缘越多的颜色 被混合到一起

@param sigmaColor Filter sigma in the color space. A 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.

//空间参数,数越大越大的区域颜色相同第三个参数大于0邻域大小与此参数无关,否则正此参数成正比正相关

@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that

farther pixels will influence each other as long as their colors are close enough (see sigmaColor

). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is

proportional to sigmaSpace.

@param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes

示例代码

Mat srcimg = imread(filename);
// Mat dst;
g_srcImage = srcimg.clone();
// bilateralFilter(srcimg, dst, 25,25*2,25/2);
// imshow("bilateralFilterimg",dst);
namedWindow("bilateralFilterimg", 1);


createTrackbar

官方说明:就是一个slider来改变相关数值大小

The function createTrackbar creates a trackbar (a slider or range control) with the specified name

and range, assigns a variable value to be a position synchronized with the trackbar and specifies

the callback function onChange to be called on the trackbar position change. The created trackbar is

displayed in the specified window winname.
参数说明

//轨迹名

@param trackbarname Name of the created trackbar.

//窗口名

@param winname Name of the window that will be used as a parent of the created trackbar.

//滑块初始位置指针类型

@param value Optional pointer to an integer variable whose value reflects the position of the

slider. Upon creation, the slider position is defined by this variable.

//滑块最大值 ,最小值始终为0

@param count Maximal position of the slider. The minimal position is always 0.

//更改回调函数

@param onChange Pointer to the function to be called every time the slider changes position. This

function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar

position and the second parameter is the user data (see the next parameter). If the callback is

the NULL pointer, no callbacks are called, but only value is updated.

//传给用户数据 全局变量可以不用考虑

@param userdata User data that is passed as is to the callback. It can be used to handle trackbar

events without using global variables.

示例代码

//双边滤波
int bilateralFilterimg(const string & filename)
{
Mat srcimg = imread(filename);
// Mat dst;
g_srcImage = srcimg.clone();
// bilateralFilter(srcimg, dst, 25,25*2,25/2);
// imshow("bilateralFilterimg",dst);
namedWindow("bilateralFilterimg", 1);
//创建轨迹条
createTrackbar("参数值:", "bilateralFilterimg", &g_nMedianBlurValue, 50, on_MedianBlur);
on_MedianBlur(g_nMedianBlurValue, 0);
/* Mat image1(srcimg.rows, srcimg.cols, srcimg.type(), Scalar(180, 120, 50));
for (int x = 0; x < srcimg.cols; x++)
{
for (int y = 0; y < srcimg.rows; y++)
{

image1.at<Vec3b>(Point(x, y))[0] = 0;// srcimg.at<Vec3b>(Point(x, y))[0];
image1.at<Vec3b>(Point(x, y))[1] =  srcimg.at<Vec3b>(Point(x, y))[1];
image1.at<Vec3b>(Point(x, y))[2] = 0;// srcimg.at<Vec3b>(Point(x, y))[2];

}
}
imshow("image1", image1);*/
waitKey(0);
return  0;
}
void on_MedianBlur(int, void *)
{
Mat g_dstImage4= g_srcImage.clone();//一次就好
//  medianBl
4000
ur(g_srcImage, g_dstImage4, g_nMedianBlurValue * 2 + 1);
bilateralFilter(g_srcImage, g_dstImage4, g_nMedianBlurValue, g_nMedianBlurValue *2, g_nMedianBlurValue /2);

imshow("bilateralFilterimg", g_dstImage4);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息